partial transparency lost in composite -watermark

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
jta2010
Posts: 6
Joined: 2012-08-14T15:56:50-07:00
Authentication code: 67789
Contact:

partial transparency lost in composite -watermark

Post by jta2010 »

Hi,

The "composite -watermark" command is not respecting the partial transparency of my PNG watermark.

I'm using ImageMagick 6.7.7-8 2012-06-20 Q16 (i.e., latest version) on Windows 2008.

Source JPG:

http://www.cuttingedgephotography.co.uk ... source.jpg

Partially-transparent PNG watermark:

http://www.cuttingedgephotography.co.uk ... ermark.png

Command:

composite -watermark 50% -gravity southeast watermark.png source.jpg output.jpg

This is what I get:

http://www.cuttingedgephotography.co.uk ... output.jpg

It seems that ImageMagick is ignoring my alpha transparency in my PNG, so any pixel that has any colour at all -- as long as it is not fully transparent -- is treated as a solid grey.

I have read about using -dissolve instead, and that gives me what I want:

http://www.cuttingedgephotography.co.uk ... lve_50.jpg

I'd like to know why it is not working with -watermark and/or if there is any workaround. From http://www.imagemagick.org/Usage/annota ... mark_image : "Before IM version 6, the options "-watermark" and "-dissolve" were broken with their handling of the alpha channel (transparency) for the overlaying image, producing some very strange effects". Perhaps this is fixed for -dissolve but still broken for -watermark? I guess I'll probably switch to "-dissolve" but I have a image-hosting framework where thousands of customers have built watermarks for use with "-watermark" and changing everything is risky. I'd like to at least know the full story. From the docs, it sounds like "-watermark" is *supposed* to support partial transparency.

Thanks,
Matt
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Contact:

Re: partial transparency lost in composite -watermark

Post by fmw42 »

composite is very old. try the more current syntax

convert background watermark -define ... -compose modulate -composite output

see
http://www.imagemagick.org/script/compose.php

If that does not work, then it might be an issue of recent versions of IM have linear grayscale. So try


convert background watermark -set colorspace RGB -define ... -compose modulate -composite output

Let us know if any of this helps.
jta2010
Posts: 6
Joined: 2012-08-14T15:56:50-07:00
Authentication code: 67789
Contact:

Re: partial transparency lost in composite -watermark

Post by jta2010 »

Hi Fred,

Thanks so much for response.

I'd already tried convert/-compose but, for me, they generated identical outputs to composite -dissolve and composite -watermark. So I don't think convert/-compose will help. Just now I also tried setting the colorspace to RGB & sRGB, but that did not cause my PNG alpha transparency to be detected/preserved.

Any other ideas? Anyone?

Regards,
Matt

Fred, here's what I got with convert/-compose... am I using these right?

convert source.jpg watermark.png -gravity southeast -compose dissolve -define compose:args=50,100 -composite output_compose_dissolve.jpg
output: http://www.cuttingedgephotography.co.uk ... ssolve.jpg (binary identical to "composite -dissolve ...")

convert source.jpg watermark.png -gravity southeast -compose modulate -define compose:args=50,100 -composite output_compose_modulate.jpg
output: http://www.cuttingedgephotography.co.uk ... dulate.jpg (binary identical to "composite -watermark ..."; same PNG alpha problem)

convert source.jpg watermark.png -set colorspace sRGB -gravity southeast -compose modulate -define compose:args=50,100 -composite output_compose_modulate_sRGB.jpg
output: http://www.cuttingedgephotography.co.uk ... e_sRGB.jpg (sRGB does not fix)

convert source.jpg watermark.png -set colorspace RGB -gravity southeast -compose modulate -define compose:args=50,100 -composite output_compose_modulate_RGB.jpg
output: http://www.cuttingedgephotography.co.uk ... te_RGB.jpg (RGB does not fix)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA
Contact:

Re: partial transparency lost in composite -watermark

Post by fmw42 »

jta2010 wrote:Hi Fred,

Thanks so much for response.

I'd already tried convert/-compose but, for me, they generated identical outputs to composite -dissolve and composite -watermark. So I don't think convert/-compose will help. Just now I also tried setting the colorspace to RGB & sRGB, but that did not cause my PNG alpha transparency to be detected/preserved.

Any other ideas? Anyone?

Regards,
Matt

Fred, here's what I got with convert/-compose... am I using these right?

convert source.jpg watermark.png -gravity southeast -compose dissolve -define compose:args=50,100 -composite output_compose_dissolve.jpg
output: http://www.cuttingedgephotography.co.uk ... ssolve.jpg (binary identical to "composite -dissolve ...")

convert source.jpg watermark.png -gravity southeast -compose modulate -define compose:args=50,100 -composite output_compose_modulate.jpg
output: http://www.cuttingedgephotography.co.uk ... dulate.jpg (binary identical to "composite -watermark ..."; same PNG alpha problem)

convert source.jpg watermark.png -set colorspace sRGB -gravity southeast -compose modulate -define compose:args=50,100 -composite output_compose_modulate_sRGB.jpg
output: http://www.cuttingedgephotography.co.uk ... e_sRGB.jpg (sRGB does not fix)

convert source.jpg watermark.png -set colorspace RGB -gravity southeast -compose modulate -define compose:args=50,100 -composite output_compose_modulate_RGB.jpg
output: http://www.cuttingedgephotography.co.uk ... te_RGB.jpg (RGB does not fix)

I am not sure you watermark image is appropriate. The underlying image is just more or less gray with a white border. Furthermore, I am not sure you can use an 8-bit alpha channel, perhaps only binary alpha channel.

I tried changing the watermark background, but it still does the same. I really suspect, you may not be able to use an 8-bit alpha channel.

But Anthony is the best to answer this.

Can you produce something that works with an older version of IM using the same images?
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot], Semrush [Bot] and 18 guests