Skip to content

Instantly share code, notes, and snippets.

@bhanuka-yd
Forked from zolthan/svg-convert.sh
Created December 18, 2019 05:06
Show Gist options
  • Select an option

  • Save bhanuka-yd/eddd1a7416568c540a62050df9ba5996 to your computer and use it in GitHub Desktop.

Select an option

Save bhanuka-yd/eddd1a7416568c540a62050df9ba5996 to your computer and use it in GitHub Desktop.
Convert SVG to PNG @2x @3x
#!/bin/bash
# I made this script to convert SVG icons for an iOS app into PNG.
# The script will create icons in 3 sizes for different screen DPIs.
find . -type f -name "*.svg" | while read f
do
echo '---'
FILENAME="${f%.*}"
echo $FILENAME
WIDTH=$(convert "$FILENAME.svg" -print "%w" /dev/null | awk '{ rounded = sprintf("%.0f", $1); print rounded; }')
convert -background none -density $(($WIDTH * 300)) -resize $(($WIDTH * 1))x "${FILENAME}.svg" "${FILENAME}@1x.png"
convert -background none -density $(($WIDTH * 300)) -resize $(($WIDTH * 2))x "${FILENAME}.svg" "${FILENAME}@2x.png"
convert -background none -density $(($WIDTH * 300)) -resize $(($WIDTH * 3))x "${FILENAME}.svg" "${FILENAME}@3x.png"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment