Page 1 of 1

PNG opacity in composition

Posted: 2014-07-21T23:45:16-07:00
by christiaan
I'm creating a composition of images with methods as described here: viewtopic.php?f=1&t=23883. For each layer I create separate image first (according all selected options in app), and then I'm merging those in one image.

The problem is with text images. For a text I create a transparent PNG image with the text using IM. The text needs to be placed over the image at a certain position, but can be transparent at 60% for instance. For normal JPEG's covering each other, the '-alpha on -channel A -evaluate set 60%' rule was working fine. Now for the transparent PNG files I get a 60% transparent black box. What am I missing here?

Code: Select all

convert
   -size 1457x1445 xc:white -gravity center
   ( "image1.jpg" -gravity center -virtual-pixel None +distort SRT '0' -geometry -0+0 ) -composite
   ( "image2.jpg" -gravity center -virtual-pixel None +distort SRT '0' -geometry -0+0 ) -composite
   ( "text.png" -alpha on -channel a -evaluate set 40% -gravity center -virtual-pixel None +distort SRT '0' -geometry -0+0 ) -composite
    -format JPEG "output.jpg"

Re: PNG opacity in composition

Posted: 2014-07-22T05:47:28-07:00
by snibgo
You command has "-evaluate set 40%". I would expect this to give 60% transparency. What is your shell? If Windows BAT, you need to double the %.

If this doesn't help, please provide sample input and output images. And say what IM version you are using, on what platform.

Re: PNG opacity in composition

Posted: 2014-07-22T06:29:57-07:00
by christiaan
Thanks snibgo. I know but that's not the problem. The image of the text is a full black box (of the image boundaries) at the opacity given with "-evaluate set 40%". The text is completely gone.

Here are some input images:
Image: https://dl.dropboxusercontent.com/u/303 ... /image.jpg
Text: https://dl.dropboxusercontent.com/u/303 ... m/text.png

I hope you can help me or point me in the right direction.

Code: Select all

$ convert -version
Version: ImageMagick 6.8.6-6 2013-08-05 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib fftw fontconfig freetype gslib jng jpeg lcms lzma png ps tiff x xml zlib

Re: PNG opacity in composition

Posted: 2014-07-22T07:07:02-07:00
by snibgo
text.png contains opaque black text on a transparent black background. If you set the entire image to a certain transparency, the text and background become identical.

Instead of setting an alpha, you could multiply it. Instead of "-evaluate set 40%", use "-evaluate multiply 0.4". That way, the text and background will have different alpha.

Re: PNG opacity in composition

Posted: 2014-07-22T07:26:36-07:00
by christiaan
Thanks snibgo, that seems to work! But is multiply giving the same results as normal opacity? I don't need special- or blending effects.

Re: PNG opacity in composition

Posted: 2014-07-22T07:36:00-07:00
by snibgo
Sorry, I don't understand you. What is "normal opacity"?

text.png has text with opacity 1.0 and background opacity 0.0. If you set the image opacity to 40%, both text and background have opacity 0.4. As they are the same colour (black), the text is not visible.

If you multiply opacity by 0.4, the background remains zero (because 0 * 0.4 = 0), but the text becomes 0.4 (because 1 * 0.4 = 0.4).

Re: PNG opacity in composition

Posted: 2014-07-22T08:47:39-07:00
by christiaan
Ah, it's multiply in that way. I was thinking of blending options like those in Photoshop. Never mind, I get it now.

The text is not always black, it can be any color. Will this code also work than?

Re: PNG opacity in composition

Posted: 2014-07-22T09:33:30-07:00
by snibgo
For different compositing methods, such as LinearLight or even one called Multiply, use "-compose X".

Yes, this will work for any colour. If it had been red instead of black, you would have seen more clearly what was happening.