Controlling opacity when overlaying an image

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
hollymcr
Posts: 9
Joined: 2009-12-01T03:56:35-07:00
Authentication code: 8675309

Controlling opacity when overlaying an image

Post by hollymcr »

I'm trying to do something that feels like it should be fairly straightforward but I'm getting into a mess....

I need to take old.png, resize to 400x400, and overlay a watermark (wmark.png), to create new.png.

This works:

Code: Select all

composite -gravity center "wmark.png" \( "old.png" -resize 400x400 \) "wmark.png" "new.png"
However, I would like to control the opacity of the overlaid wmark.png and I can't see how to do that.

Feel free to throw away what I have already! I've struggled to achieve both the resize and the overlay in one step.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Controlling opacity when overlaying an image

Post by Bonzo »

Have you tried -watermark :D

Code: Select all

composite -watermark 30% -gravity center watermark.png input.jpg output.png
To combine both you will need to "pipe" the result of one to the other with something like ( this probably will not work as is ! ):

Code: Select all

convert input.jpg -resize 500x500 miff:- | composite -watermark 30% -gravity center watermark.png - output.png
hollymcr
Posts: 9
Joined: 2009-12-01T03:56:35-07:00
Authentication code: 8675309

Re: Controlling opacity when overlaying an image

Post by hollymcr »

Bonzo wrote:Have you tried -watermark :D
I have but I've never got the hang of it.
Bonzo wrote: To combine both you will need to "pipe" the result of one to the other with something like ( this probably will not work as is ! ):

Code: Select all

convert input.jpg -resize 500x500 miff:- | composite -watermark 30% -gravity center watermark.png - output.png
[/quote]

It's a great starting point, as it does work!

However, I'm not sure what criteria define a suitable wmark.png when using this method, as the results are poor with the watermark image I am using. If I remove the -watermark I get similar results as I was getting before, I'm just still stuck on the opacity of the watermark.

Experimenting a little more, however, gets me something which does work using -dissolve:

Code: Select all

convert input.jpg -resize 500x500 miff:- | composite -dissolve 30% -gravity center watermark.png - output.png
So thanks for your method, it got me there in the end!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Controlling opacity when overlaying an image

Post by anthony »

Annotating, Watermarking Images..
http://www.imagemagick.org/Usage/annota ... termarking

This is one of the oldest set of Examples in IM Examples!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply