Page 1 of 1

Alpha channel differences between v6 and v7

Posted: 2019-05-23T05:10:12-07:00
by McGeekiest
The command I use to create a shaded text effect stopped working in ImageMagick 7 on macOS Mojave, installed with Homebrew. The command is:

Code: Select all

convert text.png -alpha Extract -blur 0x6 -shade 135x5 -alpha On -normalize +level 30% shaded.png
Given this input:

Image

In ImageMagick 6.9.10-43 I got this:

Image

In Imagemagick 7.0.7-7 I get this:

Image

It looks like the alpha channel is being handled differently between the two versions. Is this a bug in Imagemagick 7, or do I need to adjust my command?

Re: Alpha channel differences between v6 and v7

Posted: 2019-05-23T05:42:05-07:00
by snibgo
Alpha processing has changed in v7. See http://www.imagemagick.org/script/porting.php

The document http://www.imagemagick.org/script/comma ... .php#alpha under "-alpha extract" says:
and turns 'Off' the image's transparency, ... The alpha channel data is left intact just deactivated.
I think that is wrong, for v7. After doing "-alpha extract", I don't think we can re-activate the alpha channel data.

I would do this by saving the alpha channel data into a "mpr:", then restoring it. This works in both v6 and v7. Windows BAT syntax:

Code: Select all

magick ^
  text2.png ^
  -alpha Extract +write mpr:ALP ^
  -blur 0x6 -shade 135x5 -alpha On -normalize +level 30%% ^
  mpr:ALP -alpha off -compose CopyOpacity -composite ^
  s7a.png

Re: Alpha channel differences between v6 and v7

Posted: 2019-05-23T07:42:18-07:00
by fmw42
I may be wrong, but I thought that in IM 7 the equivalent of -alpha off and -alpha on was supposed to be -alpha deactivate and -alpha activate. The -alpha off permanently removes the alpha channel so that -alpha on will not return it.

From the porting guide:
-alpha activate/deactivate
enables and disables the alpha channel, respectively, with persistence. This is like on/off in Imagemagick 6. In Imagemagick 7, -alpha off will remove the alpha channel permanently such that -alpha on will not re-enable it.
So the following should work.

Code: Select all

magick text.png -alpha deactivate -blur 0x6 -shade 135x5 -alpha activate -normalize +level 30% shaded.png
But it does not and gives a weird result. I think this might be a bug.

Re: Alpha channel differences between v6 and v7

Posted: 2019-05-27T04:43:19-07:00
by McGeekiest
Thank you both.

The solution using mpr: from snibgo works perfectly:

Image

I can confirm the weird result reported by fmw42, and I cannot figure out how it could be the expected result:

Image

I'm changing my script to use the first solution. Thanks again.

Re: Alpha channel differences between v6 and v7

Posted: 2019-05-27T10:16:19-07:00
by fmw42
This is fixed in IM 7.0.8.47.