Page 1 of 1

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

Posted: 2016-06-06T13:28:20-07:00
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?

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

Posted: 2016-06-06T14:52:53-07:00
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.

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

Posted: 2016-06-06T19:46:41-07:00
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.

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

Posted: 2016-06-06T19:52:35-07:00
by fmw42
If alpha off works, in general, you should be able to turn alpha on again later in the same command.