Search code examples
textimagemagickdrawshadowimagemagick-convert

How to -draw text and -shadow it in ImageMagick?


I'm printing some text on an image with convert and I would like to decorate the text with a black shadow, I tried -blur or -gaussian but I cannot apply to the text, it is applied to the background image only. I need to use -draw command and not -annotate.

And this is the code I need to update for shadowing

-font "geometricslab703bt-bold-webfont.ttf" -fill White -pointsize 18 -draw "rotate -4 text 350,250 '---- mijn ideale ----'"

thanks in advance


Solution

  • A better, more flexible, way to work with text shadow is to render the shadow on a new layer. This method will allow you to manipulate the shadow-text, as needed, without affecting the background. Finally draw the actual text on top of the shadow after adjusting any geometric offsetting. Here's an example:

    convert -size 280x100 pattern:SMALLFISHSCALES \
      \( xc:transparent -font "Menlo" -pointsize 32 -fill black -draw "rotate -4 text 20,60 'ImageMagick'" -blur 0x1 \) \
      -geometry +2+2   -composite \
      -font "Menlo" -fill white -pointsize 32 -draw "rotate -4 text 20,60 'ImageMagick'" \
      example.png
    

    The escaped braces "\( \)" will create a new sub-image; which, will be applied to the background with -composite flag.

    enter image description here

    This solution is a little bit more labor intensive, but keeps all your effects isolated.