Adding directional drop shadows

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
vmspot
Posts: 3
Joined: 2019-09-22T05:55:19-07:00
Authentication code: 1152

Adding directional drop shadows

Post by vmspot »

Good morning everyone!
I hope someone here can help me. I have tried using search extensively and playing around with the code even longer but I can't figure this out. This is the situation. I have a blank PNG file (overlay.png 3264x600) that I want to add a caption at the top of (red background / black text 3264x124) which will result in a final png called finished.png. I have gotten this far. The part that is giving me trouble is I want to add a blurred dropshadow heading south a few pixels from behind the top captions background. So it would be a drop shadow of the 3264x124 red background at the top of the image. The final resulting image would have everything together. Can anyone point me in the right direction? Thanks.

Code: Select all

convert -background '#FF0000' -fill '#000000' -font Arial-Bold -gravity center -size 3264x124 caption:"This is a sample of text." overlay.png +swap -gravity north -composite finished.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adding directional drop shadows

Post by fmw42 »

There are many ways to add shadows. See the examples at https://imagemagick.org/Usage/fonts/

For example: https://imagemagick.org/Usage/fonts/#bevel and https://imagemagick.org/script/command- ... .php#shade and https://imagemagick.org/Usage/transform/#shade

Another ways is to create one gray text and then another of the color of your choice and composite them with the color one slightly offset and above the gray one.
vmspot
Posts: 3
Joined: 2019-09-22T05:55:19-07:00
Authentication code: 1152

Re: Adding directional drop shadows

Post by vmspot »

Thanks for the reply. I've read through all those docs before. I am trying to create a dropshadow on the background. Not the text itself. Everytime it seems to just replace the whole image with the dropshadow image. Not merge them in order.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adding directional drop shadows

Post by fmw42 »

see https://imagemagick.org/Usage/blur/#shadow

On which part are you trying to add the shadow? The text box or the final image?

Is this what you want?

Input:
Image

Code: Select all

convert -size 128x128 -background '#FF0000' -fill '#000000' -font Arial-Bold -gravity center \
caption:"This is a sample of text." \
\( +clone  -background black  -shadow 80x3+5+5 \) +swap \
-background none  -layers merge +repage \
lena.png +swap -gravity north -composite finished.png
Image

Change the +5+5 to adjust the direction. If you just want it below, then use +0+5
vmspot
Posts: 3
Joined: 2019-09-22T05:55:19-07:00
Authentication code: 1152

Re: Adding directional drop shadows

Post by vmspot »

The second one.. the textbox.

Just fixed up my code. Works perfect! Thank you so much. I truly appreciate your help.
Post Reply