Search code examples
loopsimagemagickimage-resizing

ImageMagick Resize watermark file and dissolve in a loop


ImageMagick: Version: ImageMagick 7.0.10-6 Q16 x64 2020-04-06

OS: Windows 10 64-bit operating system, x64-based processor

Hi

I have no experience with ImageMagick and I'm finding difficulties trying to create a batch file to automatically watermark all the .jpg pictures inside a folder.

The idea is that the watermarked.png file will be resized based on the .jpg file dimensions. The code below works well, the problem is that I'm trying to apply certain transparency on the watermark and this code doesn't do that. When I was trying to modify the code to use the -dissolve or -watermark operators I was getting error messages.

@echo off for %%z in ( *.jpg ) do ( magick "%%z" watermark.png ^ -resize %%[fx:t?u.w:s.w]x%%[fx:t?u.h:s.h] ^ -gravity southeast -composite ./SIGNED/Watermarked_%%z ) pause

The next code automatically watermarks all the files in a folder with a level of transparency on the watermark file. But it does not resize the watermark.png.

@echo off IF NOT EXIST SIGNED mkdir SIGNED FOR %%a in (*.jpg) DO magick composite -dissolve 50%% -gravity southEast (watermark.png  ) %%a ./SIGNED/JG2021_%%a pause

Does any of you know how to resize the watermark and apply the transparency? Thanks in advance


Solution

  • Try modifying your example command to adjust the transparency of the watermark image before reading in the main image like this...

    for %%z in ( *.jpg ) do ( magick watermark.png ^
       -channel A -evaluate multiply 0.5 +channel "%%z" +swap ^
       -resize %%[fx:t?u.w:s.w]x%%[fx:t?u.h:s.h] ^
       -gravity southeast -composite ./SIGNED/Watermarked_%%z )
    

    That reads the watermark into the command first, sets the channel to "A" to modify only the alpha channel, and uses -evaluate multiply to set the watermark to 0.5, or 50% transparent. After that the main image %z is read into the command, and using +swap it puts the images in the correct order to composite. Complete the command as in your example.