Alpha multiplying broken since upgrade to 7.x

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
olidem
Posts: 7
Joined: 2017-12-07T05:01:39-07:00
Authentication code: 1152

Alpha multiplying broken since upgrade to 7.x

Post by olidem »

Hi,
I used to combine one PNG image (with transparent pixels) with another matting image (to blend the image to transparent at the bottom).

This command worked fine with IM 6.x

Code: Select all

convert tmp.png test-gradient.png  -channel A -compose Multiply -composite out.png
Now, I am just getting an almost white image. Can you please help me?
Maybe also a link to the great collection of IM examples for Version 7 would help me, I cannot find it, only the 6.x edition.
Thanks in advance
Oliver
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha multiplying broken since upgrade to 7.x

Post by fmw42 »

I have tested a number of versions of IM 6 with:

Code: Select all

convert logo: \( -size 640x480 gradient: \) -channel A -compose multiply -composite +channel tmp.png
and do not get any change of the logo: image. What exact version of IM 6 did you use? and what platform?

I believe what you really want is:

IM 6

Code: Select all

convert logo: \( -size 640x480 gradient: \) -alpha off -compose copy_opacity -composite tmp.png
IM 7

Code: Select all

magick logo: \( -size 640x480 gradient: \) -alpha off -compose copy_opacity -composite tmp.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Alpha multiplying broken since upgrade to 7.x

Post by snibgo »

olidem wrote:Now, I am just getting an almost white image. Can you please help me?
To help you, we need to know what version(s) of IM you are using, and we need links to your input images. Otherwise, we can only guess.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha multiplying broken since upgrade to 7.x

Post by fmw42 »

This also works currently

Code: Select all

convert logo: \( -size 640x480 gradient: -alpha copy \) -alpha on -channel A -compose multiply -composite +channel tmp.png
olidem
Posts: 7
Joined: 2017-12-07T05:01:39-07:00
Authentication code: 1152

Re: Alpha multiplying broken since upgrade to 7.x

Post by olidem »

Ok, this is the test-gradient.pgn (I hope it did not destroy alpha channel by uploading)
https://imgur.com/v7BggBK

Then this is the tmp.png
https://imgur.com/v6tNBHF

Both images do have an alpha channel with transparent regions, and I want to combine them, i.e. let the image of the woman fade to transparent at the bottom part.

The result should look like this: https://imgur.com/mV5StA8
I cannot track back my old im version, must have been some homebrew'd 6.x version, now I have

Code: Select all

ImageMagick 7.0.7-9 Q16 x86_64 2017-11-03
THANKS IN ADVANCE!
olidem
Posts: 7
Joined: 2017-12-07T05:01:39-07:00
Authentication code: 1152

Re: Alpha multiplying broken since upgrade to 7.x

Post by olidem »

fmw42 wrote: 2017-12-07T10:57:01-07:00 IM 7

Code: Select all

magick logo: \( -size 640x480 gradient: \) -alpha off -compose copy_opacity -composite tmp.png
Well, my gradient is some hand-drawn custom shape, and as far as I understand your command, this would create a generic gradient?
And if you look at my uploaded pictures, I really want a pixelwise multiplication of alpha values.

BTW, was my command (which looks way simpler than your suggestions), was it wrong? It did what it should for me...
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha multiplying broken since upgrade to 7.x

Post by fmw42 »

This works fine for me on IM 6.9.9.25 Q16 Mac OSX

Code: Select all

convert image.png mask.png -channel a -compose multiply -composite +channel tmp.png
I think you forgot to enable all channels at the end using +channel.
olidem
Posts: 7
Joined: 2017-12-07T05:01:39-07:00
Authentication code: 1152

Re: Alpha multiplying broken since upgrade to 7.x

Post by olidem »

Well as I said, on IM 6.x it even worked without the +channel.

But my installation was upgraded to 7.x, and not it does not work anymore, neither with nor without the +channel.

This is my result: https://imgur.com/2yiOmu3
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Alpha multiplying broken since upgrade to 7.x

Post by GeeMack »

olidem wrote: 2017-12-10T03:51:16-07:00But my installation was upgraded to 7.x, and not it does not work anymore, neither with nor without the +channel.
I can get identical results to your first example command using your sample images and running this command with IM 6.9.9...

Code: Select all

convert tmp.png test-gradient.png -channel A -compose dstin -composite out6.png
Then to get that to work using IM 7.0.7 I just have to add "+swap" after the input images to reverse their order like this...

Code: Select all

magick tmp.png test-gradient.png +swap -channel A -compose dstin -composite out7.png
That gives me a result identical to your original command and the IM6 command I used above. I understand the alpha channel handling has been reversed in IM7, so if I encounter an issue with alpha, I can often resolve it by reversing or negating my mask, or reversing the order of the input images. Maybe this approach will be helpful.
olidem
Posts: 7
Joined: 2017-12-07T05:01:39-07:00
Authentication code: 1152

Re: Alpha multiplying broken since upgrade to 7.x

Post by olidem »

Wooohoooo! GeeMack Great! In fact, dstin did the job!

But can somebody explain this? Why is multiply not the correct operator????
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha multiplying broken since upgrade to 7.x

Post by fmw42 »

I believe there is a bug in IM 7. The command should work in either version.

tmp.png:
Image

test-gradient.png:
Image


IM 6.9.9.26: This works fine

Code: Select all

convert tmp.png test-gradient.png -channel A -compose multiply -composite +channel out6.png
Image


IM 7.0.7.14: This does not work

Code: Select all

magick tmp.png test-gradient.png -channel A -compose multiply -composite +channel out7.png
Image
olidem
Posts: 7
Joined: 2017-12-07T05:01:39-07:00
Authentication code: 1152

Re: Alpha multiplying broken since upgrade to 7.x

Post by olidem »

Ah, so I found a bug :-D Should I file a bug report somewhere?

Another thing: still you all first refer to the 6.x version. Is there any reason why people are migrating to slowly to 7.x?

Anyway, the dstin-workaround seems to work (I still do not know why).

Thank you all for your help!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha multiplying broken since upgrade to 7.x

Post by fmw42 »

I have already reported the bug.

Most Linux distros still come with IM 6 and very old versions at that. They are slow to upgrade. There are some difference between IM 6 and IM 7.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Alpha multiplying broken since upgrade to 7.x

Post by magick »

Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ https://www.imagemagick.org/download/beta/ by sometime tomorrow
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha multiplying broken since upgrade to 7.x

Post by fmw42 »

Seems to work fine in IM 7.0.7.15
Post Reply