Skip to content

Instantly share code, notes, and snippets.

@trdarr
Created November 20, 2013 03:48
Show Gist options
  • Save trdarr/7557395 to your computer and use it in GitHub Desktop.
Save trdarr/7557395 to your computer and use it in GitHub Desktop.
Scale and export (SVG, MDPI / non-Retina) app assets
#!/usr/bin/env sh
# vim: set ft=sh
mkdir -p ios
mkdir -p res/drawable-{mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi}
scale () {
infile=$1
outfile=${infile%.svg}
# 2x: iOS non-Retina / Android MDPI
rsvg-convert "$infile" > "res/drawable-mdpi/${outfile}.png"
cp "res/drawable-mdpi/${outfile}.png" "ios/${outfile}.png"
# 3x: Android HDPI (and, downscaled, LDPI)
rsvg-convert -z 1.5 "$infile" > "res/drawable-hdpi/${outfile}.png"
# 4x: iOS Retina / Android XHDPI
rsvg-convert -z 2.0 "$infile" > "res/drawable-xhdpi/${outfile}.png"
cp "res/drawable-xhdpi/${outfile}.png" "ios/${outfile}@2x.png"
# 6x: Android XXHDPI
rsvg-convert -z 3.0 "$infile" > "res/drawable-xxhdpi/${outfile}.png"
# 8x: Android XXXHDPI
rsvg-convert -z 4.0 "$infile" > "res/drawable-xxxhdpi/${outfile}.png"
}
if [ $# -gt 0 ]; then
for infile in "$@"; do
scale "$infile"
done
else
for infile in *.svg; do
scale "$infile"
done
fi
@trdarr
Copy link
Author

trdarr commented Nov 20, 2013

rsvg-convert comes from librsvg (brew install librsvg).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment