Help batch watermarking in current version on windows

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
DefendItYourselfcom
Posts: 4
Joined: 2019-03-06T15:41:46-07:00
Authentication code: 1152

Help batch watermarking in current version on windows

Post by DefendItYourselfcom »

Im using the newest version but have installed legacy features (mogrify/convert) Ive been working at batch proportionally watermarking while preserving background png transparency for 6 hours and searching old threads before I came on here to grovel for help from you guys. I tried doing this in other software (IrfanView and XnConvert) and was unable to preserve the transparency of my png background images. I tried mogrify but couldnt get syntax in there right. Bonus points if the new image can be created in a subfolder and preserves the image.png filename.

I have the following syntax that I modigied from another thread on here that works for a single file but how would I do many files at once in Windows . I tried adding bash to windows but linux was over my head. Thank you in advance for your time

magick image.png -set option:wmh "%[fx:h/3]" ( watermark.png -resize x%[wmh] ) -gravity SouthEast -geometry +15+15 -composite result.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help batch watermarking in current version on windows

Post by fmw42 »

mogrify allows you to direct to a subfolder using the -path argument. (See https://imagemagick.org/Usage/basics/#mogrify). But it must exist already. magick or convert will allow you to specify a subdirectory where you want the output to go in the command line for the output image, but it also must exist.

On Windows you need to double your % to %%. Otherwise your command works fine for me in Unix syntax with both image and watermark being transparent PNG images, using my own files on IM 7.0.8.30. See https://imagemagick.org/Usage/windows/

Please always provide your IM version and platform (assumed windows here). Also if possible provide your input images in the future.

With legacy IM, you would use convert and not magick. But convert in IM 6 does not allow the IM 7 syntax with -set option and -resize. So you do need to use IM 7 for that command line.
DefendItYourselfcom
Posts: 4
Joined: 2019-03-06T15:41:46-07:00
Authentication code: 1152

Re: Help batch watermarking in current version on windows

Post by DefendItYourselfcom »

ok thanks Ill try it at work. I read that usage link today but unfortunately it was over my head on the folder syntax I created a subfolder first but wasnt smart enough to make it work. Thank you for your time in replying
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help batch watermarking in current version on windows

Post by fmw42 »

For your command with an existing subfolder from a CMD window (not a .bat file)

Code: Select all

magick image.png -set option:wmh "%%[fx:h/3]" ( watermark.png -resize x%%[wmh] ) -gravity SouthEast -geometry +15+15 -composite path2\subfolder\result.png
DefendItYourselfcom
Posts: 4
Joined: 2019-03-06T15:41:46-07:00
Authentication code: 1152

Re: Help batch watermarking in current version on windows

Post by DefendItYourselfcom »

path2 was what i omitted is that a reference to the folder the files start in right? Will this convert all the files in the folder or just the one i replace "image.png" with or can i do *.png or is that only usable in Unix. Sorry for the noobie questions I truly appreciate the help
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help batch watermarking in current version on windows

Post by fmw42 »

Are you using Window DOS or Window 10 unix? Your syntax will differ depending upon what you need to do. The syntax you show would work in Windows DOS if you double your % to %%. In Unix, the % are kept single but you must escape your ( ... ) with \ as \( ... \). Note the space one either side of the code inside the escaped parens. You can write script loop over each image in a directory calling that command with some slight modification, depending upon how you want the output to be named. But the looping code depends upon your OS. I can show you for Unix, but not for Windows as I do not code on Windows. One of the other developers will need to help with that. That is why you need to provide your IM version and platform each time you ask a question.

path2 is just a reference for you to fill in the actual path to your subdirectory.
DefendItYourselfcom
Posts: 4
Joined: 2019-03-06T15:41:46-07:00
Authentication code: 1152

Re: Help batch watermarking in current version on windows

Post by DefendItYourselfcom »

I installed Ubuntu on Windows 10 so i could try a bash terminal but i didn't understand how folder structure worked or where I could actually have the starting files or how to get them there without a gui
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Help batch watermarking in current version on windows

Post by fmw42 »

When you open a terminal window on bash, it starts in your home directory. Do you know where your input files are located? Do you know where you have put your new output directory? Use your OS file system to find where those are. Once you know where, then use those in your commands. For example, I have two images on my desktop, called image1.png and image2.png (along with other jpg files) and an empty folder on my desktop called test. The code below assumes you want the same output names as the input, but in the output test directory.

The cd is change directory to whatever follows.

Code: Select all

cd "/Users/fred/desktop/"
for img in image*.png; do
im7 magick "$img" -set option:wmh "%[fx:h/3]" \( sailboat1.png -resize x%[wmh] \) -gravity SouthEast -geometry +15+15 -compose over -composite "/Users/fred/desktop/test/$img"
done
If you want all png images, and not just those starting with image, then

Code: Select all

cd "/Users/fred/desktop/"
for img in *.png; do
im7 magick "$img" -set option:wmh "%[fx:h/3]" \( sailboat1.png -resize x%[wmh] \) -gravity SouthEast -geometry +15+15 -compose over -composite "/Users/fred/desktop/test/$img"
done
If you want to process all files in the directory, then

Code: Select all

cd "/Users/fred/desktop/"
for img in *; do
im7 magick "$img" -set option:wmh "%[fx:h/3]" \( sailboat1.png -resize x%[wmh] \) -gravity SouthEast -geometry +15+15 -compose over -composite "/Users/fred/desktop/test/$img"
done
Post Reply