MacOS – Create MacOS style screenshots with drop shadow using Imagemagick

command lineimage processingmacosscreen capture

How do I add the drop shadow to any image with imagemagick to create the same effect that the screenshot on MacOS adds to screenshots when screencapture shadow is true?

Before and after pictures are to clarify the effect I am seeking.

Source image

Target image

Best Answer

The following appears to work. I've done it twice -- once to show the shadow more explicitly, and then once to show the desired, finished output.

# adds the shadow
convert source.png \( +clone -background black -shadow 100x40+0+16 \) \
+swap -background none -layers merge +repage output.png

# adds the additional space like MacOSX
convert output.png -bordercolor none -border 32 target.png

enter image description here

Caveats:

  1. The padding on should be 20px less on the top and 20px more on the bottom; this solution is not perfect in that regard.

  2. The OSX screenshow draws a white border around the image, including the rounded corners. I could not duplicate that.

  3. The shadow from osx screencapture looks more blurred but I don't know how to measure the blue and calibrate the solution to that.

Highlighted shadow to show shape and blurring

enter image description here