Odd "-compose blend" behavior with IM 7.0.1-6 ?

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
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Odd "-compose blend" behavior with IM 7.0.1-6 ?

Post by GeeMack »

I'm using "ImageMagick 7.0.1-6 Q16 x64 2016-05-19" (static) on Windows 7 64. I've run into what appears to be a bug in the composite operation when trying to blend an overlay. If I run this command it makes an opaque blue square with a red circle overlaid at 50% opacity as expected...

Code: Select all

magick ^
   -gravity center ^
   xc:lightblue[200x200] ^
   -fill none ^
   -stroke white ^
   -strokewidth 2 ^
   ( ^
      -background none ^
      xc:none[100x100] ^
      -fill darkred ^
      -stroke none ^
      -draw "circle 50,50 50,10" ^
   ) ^
   -define compose:args=50,50 ^
   -compose blend ^
   -composite ^
   -depth 8 ^
      img_test1.png
That command creates this image...

Image

Perfect. The output is a 200x200 blue square with an 80x80 red circle, 50% transparent, composited in the center.

Then I add just a single line to the code, a "-draw" operation. It draws a white stroked empty square on the blue square before creating and overlaying the red circle. This is the code with the added line...

Code: Select all

magick ^
   -gravity center ^
   xc:lightblue[200x200] ^
   -fill none ^
   -stroke white ^
   -strokewidth 2 ^
   -draw "rectangle 20,20 120,120" ^
   ( ^
      -background none ^
      xc:none[100x100] ^
      -fill darkred ^
      -stroke none ^
      -draw "circle 50,50 50,10" ^
   ) ^
   -define compose:args=50,50 ^
   -compose blend ^
   -composite ^
   -depth 8 ^
      img_test2.png
And this image is the result of that code...

Image

What seems to be happening here is the background of the red circle, the transparent 100x100 canvas it's drawn on, blends down to make the blue square 50% transparent in that area. I can't think of a reason why that canvas should send its 50% transparency property down to the blue layer in the second command when it doesn't act that way at all in the first command.

I've tried to flatten the image at various points through the command. I've tried setting or un-setting alpha before and/or after each layer of the image. I've tried it with "-background none" (or white or black) before creating the blue canvas. None of my simple tests seem to make a difference in the result.

Is this a bug, or am I misunderstanding something that's causing this odd behavior?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Odd "-compose blend" behavior with IM 7.0.1-6 ?

Post by snibgo »

A cure is to put "-alpha off" immediately after you draw the unfilled rectangle.

I don't know why the problem occurs, or why this cures it.
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Odd "-compose blend" behavior with IM 7.0.1-6 ?

Post by GeeMack »

snibgo wrote:A cure is to put "-alpha off" immediately after you draw the unfilled rectangle.

I don't know why the problem occurs, or why this cures it.
Thanks. I think I tried "-alpha off" after making the blue square but before the "-draw" operation, and that didn't work. Obviously this is just a small example of code to demonstrate my issue. In my real-life command I might have to "-alpha on" again further along in the sequence.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Odd "-compose blend" behavior with IM 7.0.1-6 ?

Post by fmw42 »

If alpha off works, in general, you should be able to turn alpha on again later in the same command.
Post Reply