Monday, December 6, 2010

ImageMagick - CLI image manipulation

I think ImageMagick is my new BF today. I take pictures with my phone and it embeds a lot of information into the meta-data of the actual image. Data like camera model, date/time and GPS location. Sometimes when I publish photos on the web I don't want that information to be included with the image. I started looking for a tool that would allow me to strip out the meta-data from large quantities of images.

ImageMagick to the rescue.

In a simple one line command I can remove the metadata from all of the photos in the current dir:

prompt# mogrify -strip *.jpg

I can also easily embed a watermark or other text right onto the images. This command is slightly more complicated but not too long:

prompt# for f in `ls -1`; do convert -size 500x14 xc:none -gravity center -stroke black -strokewidth 2 -annotate 0 'Indian Valley ABDSP 2010 - www.sefcik.com' -background none -shadow 100x3+0+0 +repage -stroke none -fill white -annotate 0 'Indian Valley ABDSP 2010 - www.sefcik.com' $f +swap -gravity south -geometry +0-3 -composite wm_${f}; done

This basically loops thru all of the images in the current dir, creates a new image and adds a watermark with the location of the picture and my website url to the new image. Both of these commands took seconds to run on 170 images total.

You can see the result on this image, it placed the text on the bottom center (you may need to ckick the image to enalrge it for a better view).


ImageMagick is extremely powerful for both web developers and the average user, more info about ImageMagick can be found on their website.

--

No comments:

Post a Comment