Skip to content

Instantly share code, notes, and snippets.

@richthegeek
Created March 28, 2013 17:00
Show Gist options
  • Save richthegeek/5264961 to your computer and use it in GitHub Desktop.
Save richthegeek/5264961 to your computer and use it in GitHub Desktop.
Script which converts all .svg files in the current directory into various size*color combinations. For example, "thing.svg" results in "pngs/black/16/thing.png" and "pngs/holo/256/thing.png" amongst others. Just customise sizes/colors/aliases in the script and then ./extract.sh
#!/bin/bash
sizes="16 24 32 64 128 256"
colors=("#000" "#33b5e3" "#808080")
names=("black" "holo" "grey")
count=${#names[@]}
for i in `seq 1 $count` ; do
name=${names[i - 1]}
if [ ! -d pngs/$name ] ; then
mkdir pngs/$name
fi
for size in $sizes ; do
if [ ! -d pngs/$name/$size ] ; then
mkdir pngs/$name/$size
fi
done
done
for svg in `ls *svg` ; do
png=`echo $svg | sed s/.svg/.png/`
for i in `seq 1 $count` ; do
color=${colors[i - 1]}
name=${names[i - 1]}
big=pngs/$name/$png
# export a massive one in this color...
if [ ! -f $big ] ; then
convert -depth 16 -background transparent -fill $color -colorize 100% -resize 1024x1024 $svg $big
fi
for size in $sizes ; do
this=pngs/$name/$size/$png
if [ ! -f $this ] ; then
convert $big -resize $size"x"$size $this
fi
done
done
echo "Converted $svg > $png"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment