How to Add Text Drop Shadow in ImageMagick?
Adding a drop shadow to text using the ImageMagick
convert command involves creating a text layer, duplicating
it to create a shadow, blurring and shifting that shadow layer, and
finally merging the text over the shadow onto a background. This guide
walks you through the precise command-line structures, parameters, and
syntax required to achieve a clean, professional text shadow effect.
The Basic Command Structure
To create a text drop shadow, you typically use the
magick convert command (or simply magick in
newer versions) alongside settings like -shadow and
-composite.
Here is the standard command template:
convert -size 600x200 xc:white -font Arial -pointsize 48 \
\( -background none -fill black label:"Shadow Text" -shadow 60x5+4+4 \) \
\( -background none -fill blue label:"Shadow Text" \) \
-geometry +30+30 -composite output.pngBreaking Down the Parameters
Understanding how each flag modifies the shadow allows you to customize the blur, opacity, and positioning to fit your design needs.
-shadow {opacity}x{sigma}+{x}+{y}: This is the core operator.Opacity: Controls how dark the shadow is (e.g.,
60for 60% opacity).Sigma: Controls the blur radius (e.g.,
5). A higher number creates a softer, more dispersed shadow.X and Y offsets: Controls the displacement of the shadow (e.g.,
+4+4shifts the shadow 4 pixels right and 4 pixels down).**Parentheses
\( ... \)**: These isolate the creation of the shadow layer and the text layer so they do not interfere with each other or the main background before composition. Notice that the text string inlabel:must match exactly in both layers so the shadow matches the text shape.-composite: This operator layers the generated text over the generated shadow and places them onto the base background image.
Creating an Advanced Drop Shadow with Custom Color
If you want the shadow to have a specific color tone rather than
standard black, you can use the -matrix operator or change
the background properties of the shadow layer.
convert -size 600x200 xc:lightblue -font Georgia -pointsize 50 \
\( -background none -fill Roboto label:"Graphic Design" -shadow 80x4+5+5 \) \
\( -background none -fill white label:"Graphic Design" \) \
-layers merge +repage output_custom.pngUsing -layers merge instead of -composite
is highly efficient when handling multiple overlapping layers, as it
automatically respects the virtual canvases created by the
-shadow effect without requiring manual geometry
shifting.