Applying 3d shadow but image source changes

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jdespatis
Posts: 9
Joined: 2011-06-24T06:17:57-07:00
Authentication code: 8675308

Applying 3d shadow but image source changes

Post by jdespatis »

Hello,

I'd like to create an icon for google maps, as a result I need to add a shadow to an image.
Thanks to this post:
viewtopic.php?f=1&t=13639

Based on IM example:
http://www.imagemagick.org/Usage/distorts/#shadow3d

I can create such a shadow, But with an image with a slight border like this one:
Image

I get this result, which is crappy (the border is crappy):
Image

Here is my full command:

Code: Select all

convert input.png -flip +distort SRT '0,0 1,-1 0' \( +clone -background none -shadow 60x5+0+0 -virtual-pixel Transparent +distort Affine '0,0 0,0  100,0 100,0  0,100 -100,50' \) +swap -background none -layers merge -fuzz 2% -trim +repage output.png
=> Any idea how to get a clean image ?
jdespatis
Posts: 9
Joined: 2011-06-24T06:17:57-07:00
Authentication code: 8675308

Re: Applying 3d shadow but image source changes

Post by jdespatis »

Oups image have been moved,

I've created them again for the post to be valid

If anyone has an idea...

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Applying 3d shadow but image source changes

Post by fmw42 »

just chop a few pixels off the bottom of the shadow before merging or even afterwards. see -chop http://www.imagemagick.org/Usage/crop/#chop

Then floodfill the lower left corner with transparency.


convert output.png -gravity south -chop 0x3 \
-fuzz 50% -fill none -draw "matte 0,60 floodfill" output_new.png

Image

or if you need to preserve the image size


convert \( output.png -gravity south -chop 0x3 \
-fuzz 50% -fill none -draw "matte 0,60 floodfill" \) \
\( -clone 0 -alpha off -fill black -colorize 100% -transparent black \) \
+swap -gravity northwest -compose over -composite \
output_new2.png


Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Applying 3d shadow but image source changes

Post by fmw42 »

see also the topic viewtopic.php?f=1&t=13639
and the link in it http://www.cycloloco.com/shadowmaker/

or try a little offset


convert input.png -flip +distort SRT '0,0 1,-1 0' \
\( +clone -background black -shadow 60x5+0+0 -virtual-pixel Transparent \
+distort Affine '0,0 3,-5 100,0 105,-3 0,100 -100,50' \) \
+swap -background none -layers merge -fuzz 2% -trim +repage \
output_new3.png

Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Applying 3d shadow but image source changes

Post by anthony »

This looks remarkably like a image that had a nice shaped color border, but was badly convered to a alpha shape. Now that bad convorsion needs to be fixed to clean up the border.

As it is the border that is crappy I would first remove it. A morphology erode of just the alpha channel will do the trick.
Now you can flatten it on white (recoloring those pixels) and restore the anti-aliasing of the original shape.

Code: Select all

   convert input.png -virtual-pixel transparent \
              \( +clone -channel A -morphology erode square +channel \
                 -background white -flatten \) \
             -compose In -composite   edge_cleaned.png
Image Image Image

Now if you do you shadows you will not have the crappy border messing things up.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply