0

I have more PNG images (let's say img1.png, img2_transparent.png, img3.png) and I want them flatten to one image.

Before I flatten them I set (I want second image was slightly transparent):

convert img2_transparent.png -alpha on -channel a -evaluate set 90%

Then I flatten them (order is img1.png, img2_transparent.png, img3.png):

convert *.png -flatten out.png

Result is ok, second "layer" has opacity 90%, BUT whole picture (thus all "three" layers) is "lightened". Colors are not so deep as I don't set alpha to img2_transparent.png.

How can I avoid this?

Thank you

stepan
  • 39
  • 4

1 Answers1

2

If you want the images to show up in equal measure in the resulting image, the general formula is to set the opacity of each layer to

1/(1 + number of layers underneath)

where the base layer is at full opacity. The second image is then at opacity 1/2, the third image at opacity 1/3, the fourth image is at opacity 1/4.

convert base.png \
   \( layer2.png -channel A -fx '0.5'   \) \
   \( layer3.png -channel A -fx '0.333' \) \
   \( layer4.png -channel A -fx '0.25'  \) ....

There is a well explained tutorial on Cambridge in Colour website. Scroll down to AVERAGING IMAGES IN PHOTOSHOP USING LAYERS.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432