Page 1 of 1

shadow with composite

Posted: 2013-08-14T12:27:39-07:00
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

Re: shadow with composite

Posted: 2013-09-11T19:19:43-07:00
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).