shadow with composite

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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

shadow with composite

Post by snibgo »

"-shadow" is normally used with "-layers merge", and that works.

"-shadow" can be used instead with "-composite", but it then seems to ignore the x and y offsets.

The following Windows script creates a test case. test_shad.png (a black square within a massive transparent border) is shadowed in three diferent ways, showing that the offset -5-5 is ignored for composite, but this creates an identical result to +4+4 for layers merge.

The final two tests show that composite does respect the shadow opacity and sigma.

Code: Select all

%IM%convert ^
  -size 600x600 xc:None ^
  -fill Black -draw "rectangle 275,275 325,325" ^
  test_shad.png

%IM%convert ^
  test_shad.png ^
  ( +clone -background Blue ^
    -shadow 80x2-5-5 ^
  ) ^
  +swap ^
  -background None -layers merge ^
  test_s0.png

%IM%convert ^
  test_shad.png ^
  ( +clone -background Blue ^
    -shadow 80x2-5-5 ^
  ) ^
  +swap ^
  -background None -composite ^
  test_c.png

%IM%convert ^
  test_shad.png ^
  ( +clone -background Blue ^
    -shadow 80x2+4+4 ^
  ) ^
  +swap ^
  -background None -layers merge ^
  test_sL4.png

%IM%compare -metric RMSE test_c.png test_sL4.png NULL:
rem Result is zero difference.


rem Following shows that composite respects shadow opacity.

%IM%convert ^
  test_shad.png ^
  ( +clone -background Blue ^
    -shadow 20x20-5-5 ^
  ) ^
  +swap ^
  -background None -composite ^
  test_c20f.png


rem Following shows that composite respects shadow sigma.

%IM%convert ^
  test_shad.png ^
  ( +clone -background Blue ^
    -shadow 80x20-5-5 ^
  ) ^
  +swap ^
  -background None -composite ^
  test_c20.png
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: shadow with composite

Post by anthony »

-layers merge (as with other -layers operators) use the virtual canvas offset information in image processing.

-composite is lower level and ignores virtual canvas offset information. That is on purpose and the way it is supposed to be. Instead it uses a -geometry offset and applies -gravity to that offset as part of positioning. It also does not expand virtual canvases, or images, instead it simply clips the output to the first 'background' or 'destination' input image.

The equivalent -layers operator for -composite is -layers flatten, or simply '-flatten', though it does work with more than two images, and includes a 'generated background color' image as a starting point.

-layers composite uses a mix of both virtual canvas offset and geometry offset with gravity to merge two lists of images (typically GIF animations).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply