Overlay transparanty bug

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Marcel71
Posts: 49
Joined: 2011-04-13T13:57:34-07:00
Authentication code: 8675308

Overlay transparanty bug

Post by Marcel71 »

Hi IM Team,

I use this image:
http://imgur.com/qnN2x,x9mVa

When i do the following:

Code: Select all

convert    -size 600x500 xc:"#FF0000ff"  -alpha set  ( hearts.png -resize 166x165! -channel Alpha -evaluate Divide 2 +channel ) -geometry +223+105 -compose Over -composite  final_template.png
Result looks good.

However when i do:

Code: Select all

C:\Temp\badge>convert    -size 600x500 xc:"#FF0000ff"  -alpha set  ( hearts.png -resize 166x165! -channel Alpha -eva
luate set 50% +channel ) -geometry +223+105 -compose Over -composite  final_template.png
Result is wrong, The overaly image turned totally black.

I need the second code, because the transparency is set between 1 and 100%. (and it is part from a much larger convert.

Is this a bug or am i doing something wrong?

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

Re: Overlay transparanty bug

Post by fmw42 »

On windows % needs to be escaped to %%

set 50% ===> se 50%%
Marcel71
Posts: 49
Joined: 2011-04-13T13:57:34-07:00
Authentication code: 8675308

Re: Overlay transparanty bug

Post by Marcel71 »

Result is still the same:
http://imgur.com/9oT3g

If i change the value 50% to another value, i can see the overlay becoming more or less transparent, however, still a 'box' instead of the image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Overlay transparanty bug

Post by fmw42 »

Marcel71 wrote:Result is still the same:
http://imgur.com/9oT3g

If i change the value 50% to another value, i can see the overlay becoming more or less transparent, however, still a 'box' instead of the image.
I do not see where you have posted your hearts.png image. The two original images you posted are 1) all black image and 2) a smaller all red image.

Others cannot test, if we do not have your exact image, which is hearts.png from your command.

You command seems to want to create a large red image and then overlay a half transparent hearts.png image. Is that correct?

What are you expecting? You result appears to be a red background with a smaller partially transparent red square placed on it. What are you expecting differently?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Overlay transparanty bug

Post by snibgo »

Windows needs % to be doubled only in command files, not in direct commands at the command window.

The original image is entirely black. The pretty picture is made from some of the pixels being transparent, and some opaque. The second command make all the pixels the same transparency, so it no longer contains a pretty picture.

"-evaluate multiply 0.5" might give you the effect you want.
snibgo's IM pages: im.snibgo.com
Marcel71
Posts: 49
Joined: 2011-04-13T13:57:34-07:00
Authentication code: 8675308

Re: Overlay transparanty bug

Post by Marcel71 »

Hi,

I uploaded the images somewhere else.

The hearts image:
http://gifhoster.com/hearts.png

When converting with -evaluate set 70% the result should be:
http://gifhoster.com/good_result.png

Code: Select all

C:\Temp\badge>convert    -size 600x500 xc:"#FF0000ff"  -alpha set  ( hearts.png -resize 166x165! -channel Alpha -evaluate set 70% +channel ) -geometry +233+105 -compose Over -composite final_template.png
But the result is:
http://gifhoster.com/bad_result.png
Marcel71
Posts: 49
Joined: 2011-04-13T13:57:34-07:00
Authentication code: 8675308

Re: Overlay transparanty bug

Post by Marcel71 »

ps. the

Code: Select all

-evaluate multiply 0.7
works also. But for 70% opacity the multiply is 0.3 so i need some extra calculation :)

But still i would think that -evaluate set 70% should work to, but i am glad i have a work-around.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Overlay transparanty bug

Post by snibgo »

There are a number of issues here.

1. There may be a bug in IM's resize.

Code: Select all

convert hearts.png -resize 166x165 h1.png
Pixels in hearts.png that were tranparent white become transparent black in h1.png, so they all have the same colour. (This may be because they are stored as one bit in hearts.png.) This is why, when you set them to the same alpha, they all look the same.

2. If you omit the resize but set the pixels to all the same transparency ("-set alpha 70%"), you get a blackish snowflake on a whitish background. This is the expected behaviour, but not the effect you want, apart from being the wrong size.

3. Multiplying the alpha by a certain amount gives the effect you want. Although the behaviour in (1) still occurs, it doesn't matter, because transparent pixels remain transparent (zero multiplied by anything remains zero).
snibgo's IM pages: im.snibgo.com
Post Reply