In a bash script (bash is now available on all three platforms: windows, mac and of course linux) Let’s say I want to apply a watermark to all images in a directory, in a loop, using imagemagick. Let’s say the watermark is a file named atcopyright.png (with a transparent background).
for file in *jpg
do
composite -gravity SouthWest atcopyright.png $file cpy_$file
done
…the above sort of does it. But if atcopyright.png has white lettering it’s invisible on a light background, and versa visa with dark.
Punchline question:
Is there a scriptable way to sample the SouthWest corner of the subject image, and choose between one of two files (atcopyrightLight.png or atcopyrightDark.png)…inside the for file in *jpg loop?
Yes good idea. That too kinda/sorta works. But when only the shadow appears that too is a bit weird.
Perhaps two high contrast black and white letter sets, slightly offset in both X and Y axes, would work better than a (typically) fuzzy and blurred drop shadow.
This finds the mean value in an area 100x20 in the bottom-left corner. If this is less than 0.5, it will composite copyD.png, which might be white characters on transparent background. Otherwise it composites copyL.png.
I have a close G’MIC equivalent but need to rejigger for your purposes. Won’t have the time or energy however. Since we already have a magick answer, I guess we are okay without it.
You can also do the tried and true method used by meme generators and put an outline around your text that’s the opposite (black outline on white lettering, or vice versa). This keeps it readable no matter the background.
Yes that’s probably best. I am pleased to know how to sample an image area in a script, to get an average grayscale value. That was my original question and I got the answer. Hail hail pixls.us