How to maintain transparency with "-compose" and "-flatten" on GraphicsMagick

I have a series of PNG images with transparent backgrounds that I want to overlay on the destination PNG image, which also has a transparent background. For argumentation, we say that a series of images:

  • Source Images: img1.png, img2.png, img3.png
  • Target Image: dest.png.

Since I want to overlay all the images at once, I'm going to use the convertswitch command composeas follows:

gm convert -compose Atop dest.png img1.png img2.png img3.png -flatten output.png

It seems pretty simple, but the problem is that output.png is losing transparency, and I don't know how to enable it. If I use the switch -background, I can set what transparency was for any color that I want, but I can not get it back to transparency.

Yes, I can subsequently call:

gm convert -transparency black ouput.png output2.png

but then any black in the actual image also becomes transparent.

Any help here?

+4
source share
1 answer

I ran into the same problem and I did a couple of things to make it work.

You should get what you want if you change your command to:

gm convert xc:transparent -compose Over img1.png img2.png img3.png -mosaic dest.png

You can use Atop Overdepending on the functionality that you want to use from the layout method.

mosaic flatten xc:transparent .

+2

All Articles