blurred shadow and edges of image

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?".
Locked
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

blurred shadow and edges of image

Post by javismiles »

hi :)
when i perform a quite blurred drop shadow on a text (with something like -shadow 100x5+2+2 ) and i produce a PNG of it,
im having the problem that the drop shadow that gradually fades out abruptly ends on the edges of the image,
how can i somehow extend the edges of the image to make sure all of the drop shadow is taken into consideration?
thanks so very much
Jav

javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: blurred shadow and edges of image

Post by javismiles »

the shadow is applied in my command in this way

$command =$this -> config['magic'].' -background none -fill "'.$thecolor.'" -font '.$font_selection.' -pointsize '.($thesize).' -gravity '.$thealign.' label:"'.$thetext.'" \( -clone 0 -background black -shadow "'.$shadowvalue.'" \) -compose DstOver -composite -compose Over -rotate '.$theangle.' '.$target_image.'';

and the problem is that when the shadow under the text is not very tight, when its quite blurred, which i need, then it abruptly ends against the edges of the image instead of fading out slowly,

there must be a way to automatically account for that shadow to adapt the size of the output image? or any other solution?

thank u so much
Jav

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

Re: blurred shadow and edges of image

Post by fmw42 »

Use -extend or -border to make the input image larger by supplying a background that is the same color as the edges of the image. I assume you have some constant background in your image upon which you have placed the text. Make it bigger by at least as much as 3x the shadow sigma value. You can make it bigger if you want and then afterwards you can use -trim to remove the excess border.

see
http://www.imagemagick.org/Usage/crop/#border
http://www.imagemagick.org/Usage/crop/#extent
http://www.imagemagick.org/Usage/crop/#trim

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

Re: blurred shadow and edges of image

Post by anthony »

Don't use -composite for -shadow imagees! Composite may not expand the image to account for the space of the shadow, thus it is getting clipped.

Also composite is a low level operator that does not use a 'layer offset' that shadow produces. Proper layering commands feeds the internal 'composite' operator with the correct layering offsets. As such your shadow image is probably not even positioned right (according to the arguments given to the -shadow operator)

This is why -layers merge is used, it expands the 'canvas' used to layer both images (foreground and shadow) so that the canvas contains both images in total, at the offsets specified in the images, even if the final image needs a negative offset to align the images correctly (the offset is typically removed and ignored in final result using +repage)

See IM Examples shadowing...
http://www.imagemagick.org/Usage/blur/#shadow
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Locked