Skip to content
MagickCmd › ImageMagick border, padding and shadow

ImageMagick border, padding and shadow

Add borders, pad an image to an exact canvas size, round the corners with real transparency, and add a drop shadow — with ImageMagick commands that actually work.

Add a border

magick input.jpg -bordercolor white -border 20 output.jpg
magick input.jpg -bordercolor '#e5e7eb' -border 20x40 output.jpg

-border grows the canvas: a 1000px image with a 20px border becomes 1040px wide. If the final size must stay 1000px, pad instead.

Pad to an exact canvas size

magick input.jpg -resize 1200x1200 -background white \
  -gravity center -extent 1200x1200 output.jpg

This fits the image inside the box and fills the remainder with the background — the standard requirement for marketplace product images that must all be the same dimensions. Nothing is cropped. Use -background none and a PNG output to pad with transparency instead.

Rounded corners with real transparency

There is no -round-corners operator. You build a mask by drawing one corner, mirroring it to make the other three, and copying the result into the alpha channel:

magick input.png \
  '(' +clone -alpha extract \
      -draw 'fill black polygon 0,0 0,40 40,0 fill white circle 40,40 40,0' \
      '(' +clone -flip ')' -compose Multiply -composite \
      '(' +clone -flop ')' -compose Multiply -composite ')' \
  -alpha off -compose CopyOpacity -composite output.png

The 40 values are the corner radius — change all four together. The output must be PNG or WebP. Writing this to JPEG fills the rounded corners with black, because JPEG has no alpha channel.

Drop shadow

magick input.png \
  '(' +clone -background black -shadow 60x12+0+8 ')' \
  +swap -background none -layers merge +repage output.png

-shadow replaces the image with its shadow, which is why it runs inside ( +clone … ) — then +swap puts the shadow behind the original and -layers merge flattens them.

The four numbers are opacity x blur + offsetX + offsetY. Keep the blur around 1.5× the offset for a shadow that looks natural rather than pasted on.

Shadow on a white card

magick input.png \
  '(' +clone -background black -shadow 50x14+0+10 ')' \
  +swap -background white -layers merge +repage \
  -bordercolor white -border 30 output.png

A polaroid frame

magick input.jpg -bordercolor white -border 20 \
  -bordercolor grey60 -border 1 \
  -background none -rotate 4 \
  '(' +clone -shadow 60x4+4+4 ')' +swap \
  -background none -layers merge +repage output.png

ImageMagick also has a built-in shortcut for this: -polaroid 4.


Related

Copied