Skip to content

Instantly share code, notes, and snippets.

@Andarius
Last active July 31, 2020 10:21
Show Gist options
  • Save Andarius/4967efdc01379ca7c819a8ac2574af9a to your computer and use it in GitHub Desktop.
Save Andarius/4967efdc01379ca7c819a8ac2574af9a to your computer and use it in GitHub Desktop.
Convert svg icons to png from command line
#!/bin/bash
convert(){
readonly FILENAME=`echo $1 | sed -r "s/.+\/(.+)\..+/\1/" | tr - _`
readonly SIZES=(
48 mdpi
72 hdpi
96 xhdpi
144 xxhdpi
192 hhdpi
20 '20'
40 '20@2x'
60 '20@3x'
)
for ((i=0; i<${#SIZES[@]}; i+=2)); do
res=${SIZES:$i+1:1}
size=${SIZES:$i:1}
echo "Size: $size, res: $res, output: $FILENAME-$res.png"
# Using inkscape
inkscape -w $size -h $size $1 --export-filename "$2/$FILENAME-$res.png"
# Using cairosvg https://cairosvg.org/
cairosvg --output-width $size --output-height $size -f png -o "$2/$FILENAME-$res.png" $1
done
}
convert ~/Downloads/icon.svg ~/Downloads/output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment