Created
June 13, 2018 17:09
-
-
Save stolk/a7b1b99ed86edba9976c392aa9773e9c to your computer and use it in GitHub Desktop.
Script to create Android icons from an SVG file.
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
#!/usr/bin/python | |
import sys | |
import os | |
sizes = [ | |
('xxxhdpi', 192), | |
('xxhdpi', 144), | |
('xhdpi', 96), | |
('hdpi', 72), | |
('mdpi', 48), | |
('ldpi', 32), | |
] | |
if len(sys.argv) != 4 : | |
print( "Usage: %s image.svg iconname res-dir" % ( sys.argv[0], ) ) | |
sys.exit( 1 ) | |
source = sys.argv[1] | |
iconname = sys.argv[2] | |
resdir = sys.argv[3] | |
if iconname[-4:] != ".png" : | |
print( "Can only genarate .png resources." ) | |
sys.exit( 1 ) | |
try: | |
subdirs = os.listdir( resdir ) | |
except OSError: | |
print( "Can't read directory %s" % ( resdir, ) ) | |
sys.exit( 1 ) | |
for sizename, resolution in sizes : | |
subdir = resdir + "/drawable-" + sizename | |
try: | |
contents = os.listdir( subdir ) | |
oname = subdir + "/" + iconname | |
cmd = "inkscape --export-png=%s --export-width=%d %s" % ( oname, resolution, source ) | |
os.system( cmd ) | |
except OSError: | |
print( "Skipping %s because subdir %s is missing" % ( sizename, subdir ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment