Skip to main content
Geppetto Luis
Legend
December 9, 2017
Answered

apply logo and suitable for different sizes

  • December 9, 2017
  • 5 replies
  • 4861 views

Hello to all

I do not know if it is possible to do this

I have a folder on the desktop with the name watemark

inside this folder there are 2 png files

logo_white.png

logo_black.png

I would like when I have to apply one of these logos on an image

must be done automatically must be placed on the bottom left

must analyze the surface

if dark it applies the logo_white.png

if it is clear, apply logo_black.png

second passage

I use 3 SLRs with different mpx

nikon d700 has 12 mpx

nikon d610 has 24 mpx

nikon d800 has 36 mpx

I would like the logo that is applied to have the same dimensions

on all formats.

thank you

This topic has been closed for replies.
Correct answer Kukurykus

You posted not enough informations, but I guess you just wanted to know is that possible you ask for.

Yes, it is, however I'm aware there are many (un)willing people here they could do it better and more accurately.

Anyway till anyone else propose his solution, you can try mine:

preferences.rulerUnits = Units.PIXELS

d = 20, m = 3, (h = (aD = activeDocument).height) > (w = aD.width) ? s = w : (s = h, d /= 2, m /= 1.5)

aD.selection.select([[(f = h / d), f * (d - m)], [m * f, f * (d - m)], [m * f, f * (d - 1)], [f, f * (d - 1)]])

function loop(v1, v2) {for(i = v1; i < v2; i++) v1+= hst; return v1}

blk = loop(0, l2 = (l1 = (hst = aD.histogram).length) / 2), wht = loop(l2, l1)

open(File('~/desktop/watemark/logo_' + (blk > wht ? 'white' : 'black') + '.png')),

(log = activeDocument).resizeImage(s / 7.5), (sel = log.selection).selectAll(), sel.copy()

log.close(SaveOptions.DONOTSAVECHANGES), aD.paste()

After I wrote my code I realised you wanted logo to have same dimmension irrespecitvely of opened document format.

Well you can change last 2 lines of code to this:

(sel = (log  = activeDocument).selection).selectAll(), sel.copy()

log.close(SaveOptions.DONOTSAVECHANGES), aD.paste()

however when logo has other resolution than opened image then result won't be that you expected. If so, replace this part of the first code:

(log = activeDocument).resizeImage(s / 7.5)

with

(log = activeDocument).resizeImage(null, null, aD.resolution)

Ah, and this code is of course only for a start, so you can test it and basing on the present result it gives, tell me how you'd like that was modified...

5 replies

Chuck Uebele
Community Expert
Community Expert
December 10, 2017

I wrote a script to do that years ago. Only works on Windows, as it will take a whole folder and put a logo on based on various criteria. Here's a link to it: http://uebelephoto.com/download%20center/watermark.zip 

Geppetto Luis
Legend
December 10, 2017

Kukurykus

Your script is fine for my needs

rather it goes beyond what I expected

It seems that it could be enough

but my curiosity is that this is fine for one photo at a time

if I wanted to have a batch process

so I can process more photos at the same time.

sorry if I ask too much

and it's not right that I do it

so if it takes up too much time do not do anything.

thanks again for your time

Kukurykus
Legend
December 10, 2017

Now you can play with more than one image at once. When you remove /**/ characters from the code it will work even on subfolders. I mean it's going to copy a tree of all nested folders and make their duplication. That new tree with a main folder (old name with "logo") will be created next to original one. So the structure of (sub)folders and files they contain remain the same. Difference is that each image will be saved with logo. Anyway that multi folders option probably won't be useful for you. One level folder should be completetly sufficient.

function FSf(sF, dst, i) {

     if (sF && !dst.length && !i) {

          Folder(decodeURI(dst[0] = fld = sF.parent + '/' + (nme2 = (nme1 = decodeURI(sF.name)) + ' Logo'))).create()

     }

     for(sF = Folder(sF).getFiles(); i < sF.length; i++) {

          if (sF instanceof Folder) {

               dst.push(eval((r1 = 'decodeURI(sF') + r2 =').replace(RegExp(nme1), nme2)'))

               /*if (i) fld = dst[0]; Folder(File(fld += '/' + sF.name)).create(), FSf(sF, dst, 0)*/

          }

          if (/\.(jpg|psd)$/i.test(sF.name)) {

               displayDialogs = DialogModes.NO, preferences.rulerUnits = Units.PIXELS, open(sF)

               d = 20, m = 3, (h = (aD = activeDocument).height) > (w = aD.width) ? s = w : (s = h, d /= 2, m /= 1.5)

               aD.selection.select([[(f = h / d), f * (d - m)], [m * f, f * (d - m)], [m * f, f * (d - 1)], [f, f * (d - 1)]])

               function loop(v1, v2) {for(j = v1; j < v2; j++) v1+= hst; return v1}

               blk = loop(0, l2 = (l1 = (hst = aD.histogram).length) / 2), wht = loop(l2, l1)

               open(File('~/desktop/watemark/logo_' + (blk >= wht ? 'white' : 'black') + '.png')),

               (log = activeDocument).resizeImage(s / 7.5), (sel = log.selection).selectAll(),sel.copy()

               log.close(dnsc = SaveOptions.DONOTSAVECHANGES), aD.paste(), (jpg = new JPEGSaveOptions())

               .quality = 12, aD.saveAs(File(fld.match(eval(r1 + '.path' + r2)) + '/' + sF.name), jpg), aD.close(dnsc)

          }

     }

}

FSf(Folder.selectDialog('Please select top level folder'), [], 0)

EDIT: this is a version letting you decide where you want to put your logo (corners, sides, or in center) / just edit pos(obj.bL):

function FSf(sF, dst, i) {

     if (sF && !dst.length && !i) {

          Folder(decodeURI(dst[0] = fld = sF.parent + '/' + (nme2 = (nme1 = decodeURI(sF.name)) + ' Logo'))).create()

     }

     for(sF = Folder(sF).getFiles(); i < sF.length; i++) {

          if (sF instanceof Folder) {

               dst.push(eval((r1 = 'decodeURI(sF') + r2 =').replace(RegExp(nme1), nme2)'))

               /*if (i) fld = dst[0]; Folder(File(fld += '/' + sF.name)).create(), FSf(sF, dst, 0)*/

          }

          if (/\.(jpg|psd)$/i.test(sF.name)) {

               displayDialogs = DialogModes.NO, preferences.rulerUnits = Units.PIXELS, open(sF)

               s = (h = (aD = activeDocument).height) > (w = aD.width) ? 0 : .75

               obj = {

                    tL: [1.5 - s, 1], tC: [7, 1], tR: [12.5 + s, 1], mL: [1.5 - s, 7], mC: [7, 7],

                    mR: [12.5 + s, 7], bL: [1.5 - s, 13], bC: [7, 13], bR: [12.5 + s, 13]

               }

               function pos(v) {

                    w1 = v[0], w2 = w1 + 1, h1 = v[1], h2 = h1 + 1, aD.selection.select

                    ([[w * w1, h * h1], [w * w2, h * h1], [w * w2, h * h2], [w * w1, h * h2]])

               }

               function wh(v) {return v / 15} w = wh(w), h = wh(h), pos(obj.bL)

               function loop(v1, v2) {for(j = v1; j < v2; j++) v1+= hst; return v1}

               blk = loop(0, l2 = (l1 = (hst = aD.histogram).length) / 2), wht = loop(l2, l1)

               open(File('~/desktop/watemark/logo_' + (blk >= wht ? 'white' : 'black') + '.png')),

               (log = activeDocument).resizeImage(null, null, aD.resolution), (sel = log.selection).selectAll()

               sel.copy(), log.close(dnsc = SaveOptions.DONOTSAVECHANGES), aD.paste(), (jpg = new JPEGSaveOptions())

               .quality = 12, aD.saveAs(File(fld.match(eval(r1 + '.path' + r2)) + '/' + sF.name), jpg), aD.close(dnsc)

          }

     }

}

FSf(Folder.selectDialog('Please select top level folder'), [], 0)

JJMack
Community Expert
Community Expert
December 10, 2017

geppettol66959005  wrote

second passage

I use 3 SLRs with different mpx

nikon d700 has 12 mpx

nikon d610 has 24 mpx

nikon d800 has 36 mpx

I would like the logo that is applied to have the same dimensions

on all formats.

thank you

Do you ever crop your images?  Your Cameras have a Max MP size and most likely offer other sizes images as well.  There is also  Portrait and Landscape orientations to consider.    If you crop images you finial image can be any size and have any aspect ratio.  My PlaceWatermak script is quite simple  to change to use your logo and place it into the bottom left corner of you images size for each image size to some percentage of the image height.  All you need to do is edit the first four var statement values in the script.

http://www.mouseprints.net/old/dpr/PlaceWatermark.jsx You can record using the script in an action and then batch the action.  The action could also add a layer style to the current layer after using the scrip it will be the placed logo laye that the layer style is added to.

JJMack
Kukurykus
KukurykusCorrect answer
Legend
December 9, 2017

You posted not enough informations, but I guess you just wanted to know is that possible you ask for.

Yes, it is, however I'm aware there are many (un)willing people here they could do it better and more accurately.

Anyway till anyone else propose his solution, you can try mine:

preferences.rulerUnits = Units.PIXELS

d = 20, m = 3, (h = (aD = activeDocument).height) > (w = aD.width) ? s = w : (s = h, d /= 2, m /= 1.5)

aD.selection.select([[(f = h / d), f * (d - m)], [m * f, f * (d - m)], [m * f, f * (d - 1)], [f, f * (d - 1)]])

function loop(v1, v2) {for(i = v1; i < v2; i++) v1+= hst; return v1}

blk = loop(0, l2 = (l1 = (hst = aD.histogram).length) / 2), wht = loop(l2, l1)

open(File('~/desktop/watemark/logo_' + (blk > wht ? 'white' : 'black') + '.png')),

(log = activeDocument).resizeImage(s / 7.5), (sel = log.selection).selectAll(), sel.copy()

log.close(SaveOptions.DONOTSAVECHANGES), aD.paste()

After I wrote my code I realised you wanted logo to have same dimmension irrespecitvely of opened document format.

Well you can change last 2 lines of code to this:

(sel = (log  = activeDocument).selection).selectAll(), sel.copy()

log.close(SaveOptions.DONOTSAVECHANGES), aD.paste()

however when logo has other resolution than opened image then result won't be that you expected. If so, replace this part of the first code:

(log = activeDocument).resizeImage(s / 7.5)

with

(log = activeDocument).resizeImage(null, null, aD.resolution)

Ah, and this code is of course only for a start, so you can test it and basing on the present result it gives, tell me how you'd like that was modified...

JJMack
Community Expert
Community Expert
December 9, 2017

geppettol66959005  wrote

I would like when I have to apply one of these logos on an image

must be done automatically must be placed on the bottom left

must analyze the surface

if dark it applies the logo_white.png

if it is clear, apply logo_black.png

analyze the surface if dark? What do you mean by dark color, luminosity, shadow, highlight? If it is clear what is clear? No texture, not detail a solid color.  Sizing and positioning a logo is not a  problem a single logo file may be possible to user for inverting a white one would become a black one.    Why limit yourself to Black and White.  Your logo can be place in as as smart object layer. So it can be applied or not.  That way it can also be adjusted for your  Image content.  It is possible to  change the size, blending and position if you do not like what the Script did automatically.  You could set up a Open document event to run a script like my Place watermark script the would add a logo layer the any single layer document.. All you need to do is add the test for the document to be a single layer.   Your ideal of analyzing the area is a red herring. Not well thought out or defined.

JJMack
Geppetto Luis
Legend
December 9, 2017

In fact above I wrote

(I do not know if it is possible to do this)

I thought it was very difficult to do

and you confirmed my doubt

I go on like I have done so far.

thanks for the answers

Legend
December 9, 2017

The script is quite complicated. I'm too lazy to write it for free.

I can offer a scenario

1. Select the area of the expected position of the Logo.

2. Obtain an average color using channel histograms (for example, the average value of R = SUM (histogram * n) / SUM (histogram ))

3. Deselect the selection.

4. Depending on the brightness of the color (avg_color.lab.l), select which file will be inserted as the Logo.

5. Insert (and, possibly, move to the desired position) your Logo in the document.

)