Skip to content

Instantly share code, notes, and snippets.

@aaronsnoswell
Created November 28, 2013 11:10
Show Gist options
  • Save aaronsnoswell/7690312 to your computer and use it in GitHub Desktop.
Save aaronsnoswell/7690312 to your computer and use it in GitHub Desktop.
Convert SVGs to PNGs recursively
#!/bin/sh
# Convert .svg files to .png - works on a single file or
# recursively on the given directory.
# Requries ImageMagick's `convert` function
# Author: Aaaron Snoswell
density=${2-72}
function convertsvg () {
echo "Converting '$2' -> '${2%.*}.png'"
convert -density $1 "$2" "${2%.*}".png
}
export -f convertsvg
if [ -d "$1" ] ; then
find $1 -iname "*.svg" -exec bash -c "convertsvg $density \"{}\"" \;
else
convertsvg $density $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment