Alpha channel differences between v6 and v7

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
McGeekiest
Posts: 2
Joined: 2019-05-23T04:51:20-07:00
Authentication code: 1152

Alpha channel differences between v6 and v7

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Alpha channel differences between v6 and v7

Post 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
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 channel differences between v6 and v7

Post 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.
McGeekiest
Posts: 2
Joined: 2019-05-23T04:51:20-07:00
Authentication code: 1152

Re: Alpha channel differences between v6 and v7

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Alpha channel differences between v6 and v7

Post by fmw42 »

This is fixed in IM 7.0.8.47.
Post Reply