Page 1 of 1

-alpha shape

Posted: 2019-07-14T15:16:07-07:00
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

Re: -alpha shape

Posted: 2019-07-14T16:15:47-07:00
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

Re: -alpha shape

Posted: 2019-07-15T07:06:40-07:00
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

Re: -alpha shape

Posted: 2019-07-15T10:21:49-07:00
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.