Created
July 17, 2017 18:50
-
-
Save steverichey/32b70959a526eea0c1275fadeca64e09 to your computer and use it in GitHub Desktop.
decent script to make android icons from PDF files, supports transparency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
usage () | |
{ | |
echo "Usage:\nsh icons.sh standard_icon.pdf debug_icon.pdf" | |
exit 1 | |
} | |
# usage: iconize input/file.pdf some/output/path/file.png 256 | |
# where `256` is the size to generate | |
iconize () | |
{ | |
if [ -e "$1" ] | |
then | |
convert -density 400 $1 -scale $3x$3 $2 | |
else | |
echo "(iconize) File not found: $1" | |
fi | |
} | |
# usage: single_icon hdpi input_icon.pdf path/to/res 98 | |
single_icon () | |
{ | |
iconize $2 $3/mipmap-$1/ic_launcher.png $4 | |
echo "Created $3/mipmap-$1/ic_launcher.png" | |
mogrify -strip $3/mipmap-$1/ic_launcher.png | |
} | |
# usage: android_icons input_icon.pdf path/to/res | |
android_icons () | |
{ | |
single_icon ldpi $1 $2 36 | |
single_icon mdpi $1 $2 48 | |
single_icon hdpi $1 $2 72 | |
single_icon xhdpi $1 $2 96 | |
single_icon xxhdpi $1 $2 144 | |
single_icon xxxhdpi $1 $2 192 | |
} | |
# abort if there are not exactly two arguments | |
if [ "$#" -ne 2 ] | |
then | |
usage | |
fi | |
# abort if first file is not found | |
if [ ! -e "$1" ] | |
then | |
usage | |
fi | |
# abort if second file is not found | |
if [ ! -e "$2" ] | |
then | |
usage | |
fi | |
echo "Generating standard icons from $1" | |
gs -dQUIET -dNOPAUSE -sDEVICE=pngalpha -o temp.png -sDEVICE=pngalpha -r288 $1 | |
android_icons temp.png app/src/main/res | |
echo "Generating debug icons from $2" | |
gs -dQUIET -dNOPAUSE -sDEVICE=pngalpha -o temp.png -sDEVICE=pngalpha -r288 $2 | |
android_icons temp.png app/src/debug/res | |
rm temp.png | |
echo "Done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment