Wednesday, 1 July 2009

Add shadow and border to images with ImageMagick

We’ve started using a quick ImageMagick script to add shadows and borders to images. Useful for making screen shots stand out a little clearer on our blog and wiki.

For example, in a unix shell, create the function below (either by cutting and pasting the code into your shell window or adding to you shell init scripts) :

image-shadow () {
  out=${1%.*}-shadow.${1#*.}
  in=$1
  echo "Converted file : $out"
  if [ ! -z $2 ] ; then 
    convert $in -frame $2 $out
    in=$out
  fi
  convert $in \( +clone -background black -shadow 60x5+10+10 \) \
    +swap -background white -layers merge +repage $out
}

and then run

image-shadow myimage.png

to add a shadow to the image … or run

image-shadow myimage.png 6x6

to add a shadow and 6 pixel border.

More examples and details on our wiki @ http://bemoko.com/wiki/ImageMagick