3d Shadows using Affine Shears

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
axeff

3d Shadows using Affine Shears

Post by axeff »

Hello there.
I'm totally new to ImageMagick and just want to create one effect and not totally learn all the mathematics behind.
So I would just ask you for help.
I want to create a shadow dynamicly via command line, like in this example:
Image
As you see, it's just a very small on the left bottom.

Pretty much like in this example (http://www.imagemagick.org/Usage/distorts/#shadow3d), but way smaller and maybe softer:

Code: Select all

convert standing_shape.png   -flip +distort SRT '0,0 1,-1 0' \
          \( +clone -background Black -shadow 60x5+0+0 \
             -virtual-pixel Transparent \
             +distort Affine '0,0 0,0  100,0 100,0  0,100 100,50' \
          \) +swap -background white -layers merge \
          -fuzz 2% -trim +repage   standing_shadow.jpg
But I don't really get through the coefficients of Affine Projection.
So I'd be really pleased if someone could help me out with this.
Thx
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: 3d Shadows using Affine Shears

Post by fmw42 »

Here is an image that I put a shadow on. I made it on a transparent background so it can be placed (flattened) over any background image. But you can change the background color or the other parameters.


shadowval="gray(85)" <--- brightness of shadow (larger values are brighter)
shadowblur=20 <--- blur distance around outside of shadow
shadowx=50 <--- width of shadow from bottom left corner of image
shadowy=25 <--- height of shadow from bottom left corner of image
bgcolor="none" <--- background color

Image

shadowval="gray(70)"
shadowblur=10
shadowx=50
shadowy=25
bgcolor="none"
shadowblur2=`convert xc: -format "%[fx:1.414*$shadowblur]" info:`
convert \( zelda3.png -flip +distort SRT '0,0 1,-1 0' \) \
\( +clone -background $shadowval -shadow 60x${shadowblur}+0+0 \
-virtual-pixel Transparent +distort Affine "0,0 0,0 100,0 100,0 0,100 $shadowx,$shadowy" \) \
+swap -background "$bgcolor" -layers merge \
-fuzz 2% -trim +repage -gravity east -chop ${shadowblur2}x0 zelda3_shadow.png


Image


Affine "0,0 0,0 100,0 100,0 0,100 $shadowx,$shadowy"

Due to the tricks in line 1, the coordinates in the Affine are measure from the bottom. The first 0,0 0,0 means to leave the bottom left unchanged. Similarly, 100,0 100,0 means leave the bottom right unchanged. The 0,100 $shadowx,$shadowy means shift the top right and left corners (since it is affine) by the amounts specified where x is to the left. The 100 means percentage of width or height and thus similarly for the shadowx,shadowy. So 50,25 means the x or width of the shadow (shown) will be 50% and the y or height of the shadow (shown) will be 25% of the image.

Here is a smaller shadow:

shadowval="gray(95)"
shadowblur=10
shadowx=10
shadowy=10
bgcolor="none"
shadowblur2=`convert xc: -format "%[fx:1.414*$shadowblur]" info:`
convert \( zelda3.png -flip +distort SRT '0,0 1,-1 0' \) \
\( +clone -background $shadowval -shadow 60x${shadowblur}+0+0 \
-virtual-pixel Transparent +distort Affine "0,0 0,0 100,0 100,0 0,100 $shadowx,$shadowy" \) \
+swap -background "$bgcolor" -layers merge \
-fuzz 2% -trim +repage -gravity east -chop ${shadowblur2}x0 zelda3_shadow2.png

Image
axeff

Re: 3d Shadows using Affine Shears

Post by axeff »

Thx, but I get an error...

Code: Select all

convert: magick/memory.c:437: CopyMagickMemory: Assertion `source != (const void *) ((void *)0)' failed.
Aborted
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: 3d Shadows using Affine Shears

Post by snibgo »

What OS? What version of IM? Can you provide the URL of your image?
snibgo's IM pages: im.snibgo.com
axeff

Re: 3d Shadows using Affine Shears

Post by axeff »

OS is Debian 5.0.4
IM is 6.3.7
URL of Testimage is: http://home.arcor.de/axeff159/images/project1.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: 3d Shadows using Affine Shears

Post by snibgo »

That's a very old version of IM. fmw's script works fine for me in a slightly less old 6.4.5 on Ubuntu.

I suggest you update IM.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: 3d Shadows using Affine Shears

Post by fmw42 »

I believe the earliest distorts were introduced about IM 6.3.6, so all of the ones you may need may not yet have been available by 6.3.7 or may not have been working 100%.


type

convert -list distort

and see if SRT and Affine are listed. If not your IM is too old. Best to upgrade to be sure that all bugs were worked out of these distorts.
Post Reply