I want to add a watermark logo.png
to the nature.jpg
with ImageMagick, I use the following commands:
magick nature.jpg logo.png -gravity southeast -geometry 10 10 -composite nature-wm.jpg
convert nature.jpg -resize 50% nature-50%.jpg
magick nature-50%.jpg logo.png -gravity southeast -geometry 10 10 -composite nature-50%-wm.jpg
As you can see, the watermark is smaller when adding it to an image which has large width and height, but this is not what I expected, what I expected is that the watermark can always occupy a fixed percentage of the main image, anyone know how to do this?
logo image
Original image with watermark added
50% width and height of the original image(nature-50%.jpg
)
nature-50%.jpg
with watermark added(the logo in nature-50%.jpg
looks bigger than in the original image)
CodePudding user response:
I would do that by loading the background, calculating the width of the logo relative to that (here I used 0.25 as my factor), then loading the logo and resizing before compositing:
magick background.jpg -set option:logowidth "%[fx:int(w*0.25)]" \
\( logo.png -resize "%[logowidth]x" \) \
-gravity southeast -geometry 10 10 -composite result.jpg
Regarding changing the transparency, per your comment, you could make the logo 30% opaque like this:
magick background.jpg -set option:logowidth "%[fx:int(w*0.25)]" \( logo.png -resize "%[logowidth]x" -channel A -fx "u*0.3" \) -gravity southeast -geometry 10 10 -composite result.jpg