Saturday, April 19, 2008

ImageMagick Bulk Image convert Fun

ImageMagick can do an amazing number of command line manipulation functions. ImageMagick's convert command, for example, can convert an image from one format to another and do a bunch of transformations along the way. Recently I needed to convert a whole bunch of SVG files deeply nested in a directory structure into transparent PNGs. convert, combined with a little bash magick, makes this a quick and painless task:

Let's break that down.

  1. Recursively find every file ending in .svg and pass each one separately to exec

  2. For each exec invoke a shell that executes a command from the given string with the filename getting passed as ${1}

  3. In the command call convert, changing white in the SVG to transparent in the PNG where the first argument is the SVG to convert, and the second argument is the destination PNG filename

Job complete.


  1. I think I have an idea of why you were looking into this.

  2. This comment has been removed by a blog administrator.

  3. No I don't have a video tutorial. What are you having trouble with?