Page 1 of 1

I need help with shadow efect [answered]

Posted: 2020-03-25T16:06:07-07:00
by francisco.rocha.pw
Hi,
I need help !!!
I'm new to using ImageMagick
I need to create a shadow for an image and I'm not able to do it myself.
I share here https://oc.rocha.pw/s/Ogz7WtnaBbVGyNf an example of the shadow effect that I need to be able to do
If anyone can help me in any way I will be very grateful
Best Regards
Francisco

Re: I need help with shadow efect

Posted: 2020-03-25T17:11:24-07:00
by fmw42
What is your ImageMagick version and platform? What are your example input images? Are they opaque or transparent backgrounds?

Re: I need help with shadow efect

Posted: 2020-03-26T00:57:09-07:00
by francisco.rocha.pw
Hi,
Before proceeding with the answer, I want to thank you for your interest and the time you are spending on my problem
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114
Plataform: Linux (elementaryOS)
Original Images: https://oc.rocha.pw/s/LhD9taYjSvfeRhN
Background images: Transparent
Best regards,
Francisco

Re: I need help with shadow efect

Posted: 2020-03-26T15:33:36-07:00
by fmw42
Here is one way to do that in a Unix-like environment:

Input:
Image


# lines 1-3: get width and height of input
# line 4: compute horizontal center of input
# lines 5-6: get width of logo
# line 7: compute the horizontal radius of the shadow as half the logo width
# line 8: set the vertical radius of the shadow
# line 9: set the height of the shadow image
# line 10: center vertical center of the shadow in the shadow image
# lines 11-13: draw an ellipse as the shadow on a transparent background as the shadow image and antialias its edges
# line 14: append the shadow image at the bottom of the input image
# line 15: save the result

Code: Select all

WxH=`convert cozinha.png -format "%wx%h" info:`
ww=`echo $WxH | cut -dx -f1`
hh=`echo $WxH | cut -dx -f2`
cx=`convert xc: -format "%[fx:$ww/2]" info:`
wd=`convert cozinha.png -background white -flatten \
-colorspace gray -threshold 99% -format "%@" info: | cut -dx -f1`
rx=`convert xc: -format "%[fx:$wd/2]" info:`
ry=5
ht=$((7*$ry))
cy=`convert xc: -format "%[fx:$ht/2]" info:`
convert cozinha.png \
\( -size ${ww}x${ht} xc:none -fill "graya(75%,1)" -draw "translate $cx,$cy ellipse 0,0 $rx,$ry 0,360" \
-blur 0x2 -level 50x100% \) \
-background none -smush 0 \
cosinha_shadow.png
Image

Re: I need help with shadow efect

Posted: 2020-03-26T15:55:58-07:00
by francisco.rocha.pw
Hi,
A simple word, perfect !!!
I did an initial test and the result is wonderful :-D

Seriously, I am very grateful for your precious help, it was really important for me.

Finally, if I need to change the position where the shadow is placed at the height (closest or farthest from the bottom) how could I do it?

Best regards from Portugal
Francisco

Ps .: Sorry for my bad knowledge of English
Believe me, without Google Translate it would be much worse ;-)