Page 1 of 1
Composing Transparent Images
Posted: 2019-07-29T05:07:15-07:00
by dognose
Hi,
I'm having trouble blending/composing two transparent png images
I'm using: (though I've tried a few other ways too)
composite -compose over -geometry +10+10 top.png background.png output.png
The output is mostly right, but the top image loses it's alpha transparency.
Is there a way to blend the top image into the background?
I've looked at -layers merge, but then the transparency of the base image cuts out the overlay..
Re: Composing Transparent Images
Posted: 2019-07-29T05:22:04-07:00
by snibgo
What version of IM, on what platform?
I suggest you
don't use the "composite" program. Instead use "magick" (for IM v7) or "convert" (for IM v6). With those, use the "-composite" operator, and list the two inputs in the opposite order:
Code: Select all
convert background.png top.png -geometry +10+10 -compose Over -composite output.png
Does that do what you want? The result alpha at each pixel depends on the alphas of
both inputs.
Perhaps you want "-compose Blend".
Re: Composing Transparent Images
Posted: 2019-07-29T06:37:59-07:00
by dognose
I'm still getting the same thing. Alpha on the overlay image is lost..
I'm using im 6.7.2
This is what I'm getting (with grid added to show transparency)
Vs. this is what I want
If I try to use the blend compose it doesn't compose properly
Re: Composing Transparent Images
Posted: 2019-07-29T06:39:09-07:00
by snibgo
Please post your input images.
Re: Composing Transparent Images
Posted: 2019-07-29T06:54:59-07:00
by dognose
Here you go
Re: Composing Transparent Images
Posted: 2019-07-29T07:28:50-07:00
by snibgo
V6.7.2 is very old. It may have a bug. Even if it doesn't, I suggest you upgrade.
If you want the output size to be the same as the first input, use "-composite":
Code: Select all
magick DQk2r9I.png Ws9m2Ky.png -geometry +200+10 -compose Over -composite circs2a.png
If you want the output size to be the smallest that contains all the input images, use "-layers merge". This needs one input to be repaged. If you don't want to flatten against a background colour, you need "-background none".
Code: Select all
magick DQk2r9I.png ( Ws9m2Ky.png -repage +200+10 ) -background None -compose Over -layers merge circs2b.png
Re: Composing Transparent Images
Posted: 2019-07-29T07:36:22-07:00
by dognose
Thanks, I was afraid of that, as it breaks some other scripts I use.