Merging transparent layers

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
samuelpenn
Posts: 1
Joined: 2018-12-31T06:31:25-07:00
Authentication code: 1152

Merging transparent layers

Post by samuelpenn »

I have a script which takes an XCF file and converts it to a PNG at a given scale. The XCF consists of three layers - all have transparency, and the bottom layer is set to have 50% opacity. The command I am using is this:

Code: Select all

convert -background none -layers merge -scale "$size"x"$size" "$src" "$dst"
I'm currently using the version which comes with Ubuntu 18.04: ImageMagick 6.9.7-4 Q16 x86_64 20170114

The image consists of:
1) A white circle, on a layer set to have 50% opacity.
2) A portrait, which is set within the circle.
3) A black ring, which gives a border to the circle.

Each layer has a transparency, so the end result should be a portrait in a circle, with a partially translucent white background within the circle. Everything outside the circle should be transparent.

What I get, is that the white circle (layer 1) is drawn as solid white. The layer opacity is being ignored. The parts of the image which are fully transparent are correctly drawn, but it seems to be ignoring the layer opacity.

Should the above work to give me what I want, or am I missing an option?

For background information, this used to work. I think it stopped working when I moved from Ubuntu 14.04 to Ubuntu 16.04.

Sample files showing what I'm trying to achieve:

XCF file:
https://drive.google.com/open?id=1Tk2a_ ... H4C3QNeKHE

Correct conversion (using GIMP):
https://drive.google.com/open?id=18yaf9 ... aH5RoOKnY-

Incorrect conversion (using convert):
https://drive.google.com/open?id=1o4uk5 ... A8sTk9Rd-p
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Merging transparent layers

Post by snibgo »

samuelpenn wrote:The layer opacity is being ignored. The parts of the image which are fully transparent are correctly drawn, but it seems to be ignoring the layer opacity.
As far as I know, IM cannot read XCF layer opacity.
snibgo's IM pages: im.snibgo.com
Post Reply