Copy link to clipboard
Copied
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
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 * (
Copy link to clipboard
Copied
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
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.
)
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
The script hangs at the first image
and it does not go on
as if it does not save
Copy link to clipboard
Copied
That's right. I tested it only with at least one subfolder (even when subfolders option in script was disabled).
Anyway change this part of code:
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)*/
}
to:
if (r1 = 'decodeURI(sF', r2 =').replace(RegExp(nme1), nme2)', sF instanceof Folder) {
dst.push(eval(r1 + r2))/*; if (i) fld = dst[0]; Folder(File(fld += '/' + sF.name)).create(), FSf(sF, dst, 0 )*/
}
so that should work now.
PS. when you create subfolders avoid 'Logo' and name of main folder in their names as well as special characters like: +, (, ) etc or others like spaces (I'm not sure I did something with it), as I didn't go so deep with this script to prevent all possible circumstances there can happen. Maybe later I fix it as it's not so hard.
To put logo in other palce of document use one of nine positions you find in object:
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]
}
There are shortened names: t = top, m = middle, b = bottom, L = Left, C = Center, R = Right.
Copy link to clipboard
Copied
Now the batch works well
but the logo does not fit all image sizes
sometimes it is bigger and others smaller
instead with the first script you posted
it was fine and kept the size
Copy link to clipboard
Copied
Change:
s = (h = (aD = activeDocument).height) > (w = aD.width) ? 0 : .75
to:
s = .75, hw = (h = (aD = activeDocument).height); if (h > (w = aD.width)) s = 0, hw = w
and:
(log = activeDocument).resizeImage(null, null, aD.resolution), (sel = log.selection).selectAll()
sel.copy(), log.close(dnsc = SaveOptions.DONOTSAVECHANGES), aD.paste(), (jpg = new JPEGSaveOptions())
for:
(log = activeDocument).resizeImage(hw / 7.5), (sel = log.selection).selectAll(), sel.copy()
log.close(dnsc = SaveOptions.DONOTSAVECHANGES), aD.paste(), (jpg = new JPEGSaveOptions())
You can try this loop over obj on some opened document. You'll see what colour your logo will have in each of 9 positions:
displayDialogs = DialogModes.NO, preferences.rulerUnits = Units.PIXELS
s = .75, hw = (h = (aD = activeDocument).height); if (h > (w = aD.width)) s = 0, hw = w
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)
for(i in obj) {
function loop(v1, v2) {for(j = v1; j < v2; j++) v1+= hst
; return v1} pos(obj) 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(hw / 7.5), (sel = log.selection).selectAll(), sel.copy()
log.close(dnsc = SaveOptions.DONOTSAVECHANGES), aD.paste(), aD.selection.deselect()
}
Copy link to clipboard
Copied
A big job, thank you very much
Last question
if the watemar folder I would like to keep it in the same folder as the script
and not on the desktop what should be changed
I tried to make this change but it does not work
open (File ('~ / watemark / logo_' + (blk> = wht? 'white': 'black') + '.png')),
Copy link to clipboard
Copied
open(File(File($.fileName).path + '/logo_' + (blk >= wht ? 'white' : 'black') + '.png')),
Fortunately you don't need it, but don't enable subfolders option. It doesn't work like it should. Like before I said, I'll fix it.
Copy link to clipboard
Copied
Thanks for everything.
Copy link to clipboard
Copied
function FSf(sF, dst, i) {
if (sF && !dst.length) {
Folder(dst[0] = sF.parent + '/' + (nme2 = (nme1 = decodeURI(sF.name)) + ' Logo')).create()
}function gF(v) {return Folder(sF).getFiles(RegExp(v + '[^\.]+$'))}
for(sF = gF('^').concat(gF('\\.')); i < sF.length; i++) {
if (r1 = 'decodeURI(sF', r2 =').replace(RegExp(nme1), nme2)', sF instanceof Folder) {
dst.push(eval(r1 + r2)); Folder(File(dst[dst.length - 1])).create(), FSf(sF, dst, 0)
}
if (/\.(jpg|psd)$/i.test(sF.name)) {
displayDialogs = DialogModes.NO, preferences.rulerUnits = Units.PIXELS, open(sF)
s = .75, hw = (h = (aD = activeDocument).height); if (h > (w = aD.width)) s = 0, hw = w
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(File($.fileName).path + '/logo_' + (blk >= wht ? 'white' : 'black') + '.png')),
(log = activeDocument).resizeImage(hw / 7.5), (sel = log.selection).selectAll(), sel.copy()
log.close(dnsc = SaveOptions.DONOTSAVECHANGES), aD.paste(), (jpg = new JPEGSaveOptions())
.quality = 12, aD.saveAs(File(dst[dst.length - 1].match(eval(r1 + '.path' + r2)
.replace(/([\$\+\(\[\^])/g, '\\$1')) + '/' + sF.name), jpg), aD.close(dnsc)
}
}
}
#target photoshop
function SYS(v) {return File(Folder.desktop + '/sys.' + v)} sys = SYS('txt'), bat = SYS('bat')
if (Folder(prst = (strt = Folder.startup) + '/presets').getFiles('watermark').length) {
bat.remove(), FSf(Folder.selectDialog('Please select top level folder'), [], 0)
}
else {
File(prst + '/watermark').createAlias(fN = File($.fileName))
sys.open('w'), sys.write('ping 127.0.0.1 -n 2 > nul\r\start "' +
strt.fsName + '\\photoshop.exe" ' + '"' + fN.fsName + '"\r\exit')
sys.close(), File('~/Desktop/sys.txt').rename('sys.bat')
File(String(sys).replace(/txt/, 'bat')).execute(), photoshop.quit()
}
Now you can use subfolders with special characters in folders names, their names can be repeated and contain name of main folder as well as logo name. I added also special part. After first time you open your script it quits Ps, then lauch it again, and meantime it set shortcut in your Photoshop folder, so it can link to folder where you keep your script. Every next time you open Photoshop your script will be on the list of available scripts.
For those who want to use this script. Create 2 logo's. For example white and black and name them: logo_white.png and logo_black.png, then put in watermark folder together with script. If something doesn't work let me know.
Btw this forums has the worse editor I ever met 😕
Copy link to clipboard
Copied
Kukurykus
I use mac and I'm having problems
it does not work
maybe and suitable for windows
Copy link to clipboard
Copied
It uses Windows batch, as I'm user of this system. If you're not that new convinience won't work for you, replace then:
if (Folder(prst = (strt = Folder.startup) + '/presets').getFiles('watermark').length) {
with:
if (!/w/.test($.os) || Folder(prst = (strt = Folder.startup) + '/presets').getFiles('watermark').length) {
(if 'w' letter in RegEx code isn't sufficient, type whole 'windows' word)
Copy link to clipboard
Copied
I tried to make the change but it does not work
if someone on the forum can make it compatible with mac
I think it's useful for everyone.
Copy link to clipboard
Copied
What do you mean saying 'it does not work'? That the script work the way like it used (so doesn't quit after executing script to be launched again?) or something else? I hope there is not any error and rest of script works. That change I made was to disable option for linking script from Photoshop Folder in case of mac users. Otherwise you had error like you experienced before. So generally script works for you now (but without that additional action I added last time) or it breaks again?
Copy link to clipboard
Copied
In my opinion the error lies in the fact that mac does not use .bat files
then an error comes out on this and it does not keep me going.
Copy link to clipboard
Copied
Yes, it's why I posted a change to last full version of code:
if (!/w/.test($.os) || Folder(prst = (strt = Folder.startup) + '/presets').getFiles('watermark').length) {
Just if there is 'w' letter in name of mac system you may replace (!/w/.test($.os) with (!/Windows/.test($.os) (starting with with (big) 'W', not (small) 'w' like I wrote previously. I'm still not sure code with that change worked for you or not, but maybe you misunderstood me in last post, so let's investigate the problem.
/w/.test($.os) checks are you Windows user, while invertion, so !/w/.test($.os) checks aren't you Windows user, so in this case almost the same like 'Are you mac User'.
WINDOWS USER:
(at the first use of script:)
1) in the first part of 'if' statement script asks 'Are you Macintosh User?', the result is FALSE
2) in the second part of 'if' setatement script asks 'Is "watermark' link present in Ps folder?', the result is FALSE
3) it starts 'else' statement, where it runs .bat file, which run script again
(as continuation or at the every next use of script:)
4) (AGAIN) in the first part of 'if' statement scripts asks 'Are you Macintosh User?', the result is FALSE
5) (AGAIN) in the second part of 'if' setatement script asks 'Is "watermark' (...) in Ps folder?', the result is TRUE
6) here the main function of script starts...
MACINTOSH USER:
(at the first and every next use of script:)
1) in the first part of 'if' statement script asks 'Are you Macintosh User?', the result is TRUE
2) it doesn't check answer for second question of 'if' statement, so the more, it never goes to 'else' part
3) here the main function of script starts...
--------------------------------------------------------------------------------------------------------------------
I can't understand why it doesn't work for you. As you see there is no chance that .bat is executed in your case as it is 'else' part content, and that is not allowed to be ever performed in mac case. What error are you getting, and in which line?
---------------------------------------------------------------------------------------------------------------------
I'd like to get to know reason of this behaviour, if whole script (with that new part) doesn't work indeed.
Anyway the simplest way to make it working is changing:
#target photoshop
function SYS(v) {return File(Folder.desktop + '/sys.' + v)} sys = SYS('txt'), bat = SYS('bat')
if (!/w/.test($.os) || Folder(prst = (strt = Folder.startup) + '/presets').getFiles('watermark').length) {
bat.remove(), FSf(Folder.selectDialog('Please select top level folder'), [], 0)
}
else {
File(prst + '/watermark').createAlias(fN = File($.fileName))
sys.open('w'), sys.write('ping 127.0.0.1 -n 2 > nul\r\start "' +
strt.fsName + '\\photoshop.exe" ' + '"' + fN.fsName + '"\r\exit')
sys.close(), File('~/Desktop/sys.txt').rename('sys.bat')
File(String(sys).replace(/txt/, 'bat')).execute(), photoshop.quit()
}
to:
#target photoshop
FSf(Folder.selectDialog('Please select top level folder'), [], 0)
But still, if someone else from mac users want to try this script in original shape (so without creating shortcut to a script) and you say there's error then that would be good to see why it happens...
Copy link to clipboard
Copied
This is the mistake that comes out of me
Copy link to clipboard
Copied
Post the full script you users function FSf seems to start on line 1 of the script posted here.