-alpha shape

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
Marcel71
Posts: 49
Joined: 2011-04-13T13:57:34-07:00
Authentication code: 8675308

-alpha shape

Post by Marcel71 »

Hi All,

When i follow the instructions on the following page to create a red heart, in IM 6 it works, but in IM7 it fails:
https://www.imagemagick.org/Usage/masking/#alpha_shape

IM6

Code: Select all

convert -font WebDings -pointsize 24 label:Y +trim +repage  -negate   heart_mask.gif
convert heart_mask.gif  -background Red -alpha Shape  heart_red.png
Results in: Image

IM 7.0.8-53

Code: Select all

convert -font WebDings -pointsize 24 label:Y +trim +repage  -channel rgb -negate   heart_mask.gif
convert heart_mask.gif  -background Red -alpha Shape  heart_red.png
Results in: Image

Not sure what i am doing wrong. Any hints would be appreciated.

Regards,
Marcel
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -alpha shape

Post by fmw42 »

It could just be how IM 7 handles alpha. But from my perspective, it looks like a bug to me in IM 7. However, there is an easy fix. First there is no +trim in IM 7. To fix the alpha issue, just add -negate in your second command. But note that in IM 7, use magick, not convert, unless you have an alias set up.

This works for me.

Code: Select all

magick -font WebDings -pointsize 24 label:Y -channel rgb -negate   heart_mask.gif
magick heart_mask.gif  -negate -background Red -alpha Shape  heart_red.png
or just remove both negates as

Code: Select all

magick -font WebDings -pointsize 24 label:Y  heart_mask.gif
magick heart_mask.gif  -background Red -alpha Shape  heart_red.png
Marcel71
Posts: 49
Joined: 2011-04-13T13:57:34-07:00
Authentication code: 8675308

Re: -alpha shape

Post by Marcel71 »

Thanks for the reply.

When i do the same thing with text, i get a scrambled result:

In IM6

Code: Select all

convert -background none -font Arial -pointsize 140 -strokewidth 14 -stroke black -fill none label:LEGEND -fill black -stroke none label:LEGEND -compose DstIn -composite -alpha extract -blur 1 -background "red" -alpha shape shape.png
Result: Image

In IM7

Code: Select all

magick -background none -font Arial -pointsize 140 -strokewidth 14 -stroke black -fill none label:LEGEND -fill black -stroke none label:LEGEND -compose DstIn -composite -alpha extract -blur 1 -negate -background red -alpha shape shape.png
Result: Image

Maybe anyway something wrong with the -alpha shape command?
(above is part of a longer command, but it illustrates the problem)

regards,
Marcel
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -alpha shape

Post by fmw42 »

I do not get that IM 7 result. But the two results are different.

You need to use parenthesis. And also negate the alpha extract image. This makes them similar, but the final IM 7 image is not blurred properly.

Try (unix syntax)

Code: Select all

convert -background none -font Arial -pointsize 140 -strokewidth 14 \( -stroke black -fill none label:LEGEND +write tmp6a.png \) \( -fill black -stroke none label:LEGEND +write tmp6b.png \) -compose DstIn -composite +write tmp6c.png -alpha extract -blur 1 -background "red" -alpha shape shape6.png

Code: Select all

magick -background none -font Arial -pointsize 140 -strokewidth 14 \( -stroke black -fill none label:LEGEND +write tmp7a.png \) \( -fill black -stroke none label:LEGEND +write tmp7b.png \) -compose DstIn -composite +write tmp7c.png -alpha extract -blur 1 -negate -background "red" -alpha shape shape7.png

I have included some temporary image to see where the issue is failing. The text results before the alpha extract are identical. But then it fails at the blur.

So there are two bugs:

1) IM 7 -alpha shape needs a negated image

2) IM 7 -blur is not the same as with IM 6 on the alpha image. This may be due to the blurring.
Post Reply