Skip to content

Instantly share code, notes, and snippets.

@igorkulman
Forked from lopis/svg-convert.sh
Last active May 25, 2023 16:42
Show Gist options
  • Save igorkulman/db6d725d3e2bed67180aa0c7a908c3a4 to your computer and use it in GitHub Desktop.
Save igorkulman/db6d725d3e2bed67180aa0c7a908c3a4 to your computer and use it in GitHub Desktop.
SVG to PNG convert and resize
#!/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 "$(cd ..; pwd)" . -type f -name "*.svg" | while read f
do
FILENAME="${f%.*}"
echo '---'
inkscape -W "$FILENAME.svg"
WIDTH=$(inkscape -W "$FILENAME.svg" | awk '{ rounded = sprintf("%.0f", $1 * 0.5); print rounded; }')
inkscape --export-width=$(($WIDTH * 1)) -z -e "${FILENAME}@1x.png" "${FILENAME}.svg"
inkscape --export-width=$(($WIDTH * 2)) -z -e "${FILENAME}@2x.png" "${FILENAME}.svg"
inkscape --export-width=$(($WIDTH * 3)) -z -e "${FILENAME}@3x.png" "${FILENAME}.svg"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment