Android MustHave: a script to create PNGs for all DPIs from vector and raster sources


Today I want to share with you the script that creates icons from the most popular vector formats: .ai, .svg, .eps, .ps and some other, such as .pdf and .png.

The script converts all files with predefined file format from current directory to Android-specific resource folders: drawable-mdpi, drawable-hdpi, drawable-xhdpi, drawable-xxhdpi and drawable-xxxhdpi. Output PNG sizes are:

  • 48×48 (1.0x baseline) for medium-density
  • 72×72 (1.5x) for high-density
  • 96×96 (2.0x) for extra-high-density
  • 180×180 (3.0x) for extra-extra-high-density
  • 192×192 (4.0x) for extra-extra-extra-high-density (launcher icon only)

as Google reccomends in Supporting Multiple Screens guide.

Source code:

mkdir ../drawable-mdpi
mkdir ../drawable-hdpi
mkdir ../drawable-xhdpi
mkdir ../drawable-xxhdpi
mkdir ../drawable-xxxhdpi

for f in *.ai;
echo “Processing $f”
inkscape -D -w 48 -h 48 -e ../drawable-mdpi/${f/.ai}.png ./$f
inkscape -D -w 72 -h 72 -e ../drawable-hdpi/${f/.ai}.png ./$f
inkscape -D -w 96 -h 96 -e ../drawable-xhdpi/${f/.ai}.png ./$f
inkscape -D -w 180 -h 180 -e ../drawable-xxhdpi/${f/.ai}.png ./$f
inkscape -D -w 192 -h 192 -e ../drawable-xxxhdpi/${f/.ai}.png ./$f


Convertation is performed by Inkscape. If you still don’t have it, you should download it from the link above.


Just save the code to <name>.sh and start it with bash. If you use Windows, install Cygwin. This code is tuned for .ai files, you can change it to anyone supported by Inkscape. Additional export parameters are described here.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s