/
android-iconify.py
executable file
·69 lines (60 loc) · 2.25 KB
/
android-iconify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/python
"""
@file android_iconify.py
@author Michael Mitchell
@date Sept 18, 2011
@brief Automate the re-sizing of icons for Android using python and ImageMagick.
@usage android-iconify.py icon_file_to_convert.png
Naming and sizing based on suggested developer practices here:
http://developer.android.com/guide/practices/ui_guidelines/icon_design.html
"""
import os, sys
if len(sys.argv) != 2: # the program name and image file.png
sys.exit("Usage: android_iconify.py icon_file_to_convert.png")
file = sys.argv[1]
if file.endswith('.png'):
# create directory structure
newdir = ('./res')
if not os.path.exists(newdir):
os.mkdir(newdir)
newdir = ('./res/drawable-ldpi')
if not os.path.exists(newdir):
os.mkdir(newdir)
newdir = ('./res/drawable-mdpi')
if not os.path.exists(newdir):
os.mkdir(newdir)
newdir = ('./res/drawable-hdpi')
if not os.path.exists(newdir):
os.mkdir(newdir)
newdir = ('./res/drawable-xhdpi')
if not os.path.exists(newdir):
os.mkdir(newdir)
newdir = ('./res/drawable-xxhdpi')
if not os.path.exists(newdir):
os.mkdir(newdir)
# drawable-ldpi
new = ('./res/drawable-ldpi/ic_launcher_' + file)
os.system ("convert %s -resize 36x36 %s" % (file, new))
new = ('./res/drawable-ldpi/ic_stat_notify_' + file)
os.system ("convert %s -resize 18x18 %s" % (file, new))
# drawable-mdpi
new = ('./res/drawable-mdpi/ic_launcher_' + file)
os.system ("convert %s -resize 48x48 %s" % (file, new))
new = ('./res/drawable-mdpi/ic_stat_notify_' + file)
os.system ("convert %s -resize 24x24 %s" % (file, new))
# drawable-hdpi
new = ('./res/drawable-hdpi/ic_launcher_' + file)
os.system ("convert %s -resize 72x72 %s" % (file, new))
new = ('./res/drawable-hdpi/ic_stat_notify_' + file)
os.system ("convert %s -resize 36x36 %s" % (file, new))
# drawable-xhdpi
new = ('./res/drawable-xhdpi/ic_launcher_' + file)
os.system ("convert %s -resize 96x96 %s" % (file, new))
new = ('./res/drawable-xhdpi/ic_stat_notify_' + file)
os.system ("convert %s -resize 48x48 %s" % (file, new))
# drawable-xxhdpi
new = ('./res/drawable-xxhdpi/ic_launcher_' + file)
os.system ("convert %s -resize 144x144 %s" % (file, new))
new = ('./res/drawable-xxhdpi/ic_stat_notify_' + file)
os.system ("convert %s -resize 64x64 %s" % (file, new))
print "Complete"