Page 1 of 1

Help with round corners and drop shadows.

Posted: 2009-03-14T15:42:46-07:00
by mrubinsk
Can anyone tell me what I'm doing wrong here? I have a convert command that used to work in an older version of IM, but is now broken on recent versions. I'm creating rounded edges with a drop shadow on a transparent background.

If I do two separate commands it works like so:

convert -size 150x113 xc:none -stroke none -draw "roundRectangle 5,5 148,111, 12,12" img_in.jpg -compose SrcIn -composite img_middle.png

and then

convert img_middle.png \( +clone -background black -shadow 80x4+3+3 \) +swap -background none -mosaic final.png

Can someone explain to me why the following, combined command will not work (I get a completely transparent image)?

convert -size 150x113 xc:none -stroke none -draw "roundRectangle 5,5 148,111, 12,12" img_in.jpg -compose SrcIn -composite \( +clone -background black -shadow 80x4+3+3 \) +swap -background none -mosaic final.png

Any help would me *most* appreciated. I've killed way too many days torturing myself over this.

Thanks!
Mike
mrubinsk@horde.org

Re: Help with round corners and drop shadows.

Posted: 2009-03-14T18:34:59-07:00
by fmw42
mrubinsk wrote:Can anyone tell me what I'm doing wrong here? I have a convert command that used to work in an older version of IM, but is now broken on recent versions. I'm creating rounded edges with a drop shadow on a transparent background.

If I do two separate commands it works like so:

convert -size 150x113 xc:none -stroke none -draw "roundRectangle 5,5 148,111, 12,12" img_in.jpg -compose SrcIn -composite img_middle.png

and then

convert img_middle.png \( +clone -background black -shadow 80x4+3+3 \) +swap -background none -mosaic final.png

Can someone explain to me why the following, combined command will not work (I get a completely transparent image)?

convert -size 150x113 xc:none -stroke none -draw "roundRectangle 5,5 148,111, 12,12" img_in.jpg -compose SrcIn -composite \( +clone -background black -shadow 80x4+3+3 \) +swap -background none -mosaic final.png

Any help would me *most* appreciated. I've killed way too many days torturing myself over this.

Thanks!
Mike
mrubinsk@horde.org

I would think that adding parens to your first section (as below) should work (with or without the -respect-parenthesis), but the +clone in the second parens is cloning xc:none rather than the result of the first parens. This may be a bug. But hopefully Anthony or Magick will know for sure or and can explain why it does not work as expected.

convert -respect-parenthesis \
\( -size 150x113 xc:none -stroke none \
-draw "roundRectangle 5,5 148,111, 12,12" img_in.jpg -compose SrcIn -composite \) \
\( +clone -background black -shadow 80x4+3+3 \) \
+swap -background none -mosaic img_final.png


In the meantime, you can do this and it will work.

convert -size 150x113 xc:none -stroke none \
-draw "roundRectangle 5,5 148,111, 12,12" \
img_in.jpg -compose SrcIn -composite miff:- |\
convert - \( +clone -background black -shadow 80x4+3+3 \) \
+swap -background none -mosaic img_final.png

Re: Help with round corners and drop shadows.

Posted: 2009-03-17T19:23:21-07:00
by anthony
The -composite operation should have removed all images in the current image sequence and replace them with a single composited result.

The parenthesis should not be needed. However as you are using -mosaic later
you will need to reset the -compose setting back to 'Over'.

The -respect-parenthesis may or may not do this, and the compose setting would have been inserted into the image and thus get used as -compose would have been reset to underfined.

It is a complex and obtuse problem as the IM command line API uses the images meta-data themselves to store 'global' settings like -compose instead of keeping a separate database of such settings. As such it gets messy with no clear cut division of meta-data vs working settings being used by various operations. A long term problem that will probably need a major version change to solve.

Re: Help with round corners and drop shadows.

Posted: 2009-03-17T19:41:27-07:00
by fmw42
anthony wrote:The -composite operation should have removed all images in the current image sequence and replace them with a single composited result.

The parenthesis should not be needed. However as you are using -mosaic later
you will need to reset the -compose setting back to 'Over'.

Interesting.

This works:

convert -size 150x113 xc:none -stroke none \
-draw "roundRectangle 5,5 148,111, 12,12" img_in.jpg -compose SrcIn -composite \
-compose over \( +clone -background black -shadow 80x4+3+3 \) \
+swap -background none -mosaic img_final.png

but this loses the shadow:

convert -size 150x113 xc:none -stroke none \
-draw "roundRectangle 5,5 148,111, 12,12" img_in.jpg -compose SrcIn -composite \
\( +clone -background black -shadow 80x4+3+3 \) \
+swap -compose over -background none -mosaic img_final.png

So placement of the resetting of -compose over is very critical. I think it makes some sense now where it is placed to make it work.

Re: Help with round corners and drop shadows.

Posted: 2009-03-17T20:39:32-07:00
by anthony
That second example I would regard as a bug. The -compose Over is needed but it should work in both the examples given.

If either example was to break I would have expected it to be the first, and not the second. So i find it even stranger! Report this as a bug!