How to Add a Drop Shadow in ImageMagick?
Adding a professional drop shadow to an image using ImageMagick’s
convert command involves a specific sequence of duplicating
the image, creating a blurred shadow mask, and compositing the original
image on top. This guide breaks down the exact command-line syntax,
explains what each parameter does, and provides a practical example so
you can add depth to your digital images instantly.
The Standard Drop Shadow Command
To create a clean, modern drop shadow, you need to use a single, chained ImageMagick command. Here is the standard syntax used to achieve this effect:
magick convert input.png \( +clone -background black -shadow 80x5+10+10 \) +swap -background none -layers merge +repage output.pngNote: If you are using ImageMagick v7 or newer, you can simply use
magickinstead ofmagick convert. If you are on Windows PowerShell, you do not need to escape the parentheses with backslashes, so use(and)instead of\(and\).
Breaking Down the Parameters
Understanding how each flag works allows you to customize the intensity, blur, and position of your shadow:
\( +clone ... \): This creates a copy of your original image in memory to work on. The operations inside the parentheses will only apply to this duplicate layer, which becomes the shadow.-background black: Sets the color of the drop shadow. While black is standard, you can change this to gray or any hex color code.-shadow 80x5+10+10: This is the core engine of the effect. It follows the geometry format:{opacity}x{sigma}+{x-offset}+{y-offset}.80: The opacity of the shadow (0 to 100).5: The softness or blur radius of the shadow. Higher numbers mean a softer, more spread-out shadow.+10: The horizontal offset. Positive numbers move the shadow to the right.+10: The vertical offset. Positive numbers move the shadow downward.+swap: Swaps the layer order so that the original image sits on top of the newly created shadow layer.-background none: Ensures that the background canvas behind the shadow remains transparent, preserving the image’s ability to overlay nicely on websites or documents.-layers merge: Flattens the original image layer and the shadow layer into a single cohesive graphic.+repage: Resets the canvas canvas geometry canvas to fit the new, slightly larger dimensions caused by the shadow offset.
Customizing Your Shadow
You can adjust the parameters to match different design aesthetics.
For a subtle, modern “soft glow” look that lifts the image straight off the page rather than casting a directional light, you can set the offsets to zero and increase the blur:
magick convert input.png \( +clone -background black -shadow 60x10+0+0 \) +swap -background none -layers merge +repage output.pngFor a hard, retro pop-art shadow, reduce the blur to zero and increase the opacity:
magick convert input.png \( +clone -background `#555555` -shadow 100x0+15+15 \) +swap -background none -layers merge +repage output.png