Last active
December 26, 2018 13:06
-
-
Save oliexdev/e08caeb3fa0ba90fdb5857661512656c to your computer and use it in GitHub Desktop.
SVG icon to png scripts for Android
This file contains hidden or 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 | |
""" | |
@file android_iconify.py | |
@license GPLv3 | |
@author [email protected] | |
@date copyright 2018 | |
@brief Automate the re-sizing of icons for Android using python and rsvg-convert based on Michael Mitchell python script | |
@usage android-iconify.py icon_file_to_convert.svg | |
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] | |
filename = os.path.splitext(sys.argv[1])[0] | |
if file.endswith('.svg'): | |
# 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) | |
newdir = ('./res/drawable-xxxhdpi') | |
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_' + filename + ".png") | |
os.system ("rsvg-convert -w 18 -h 18 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 24 -h 24 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 36 -h 36 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 48 -h 48 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 72 -h 72 %s -o %s" % (file, new)) | |
# drawable-xxxhdpi | |
new = ('./res/drawable-xxxhdpi/ic_' + filename + ".png") | |
os.system ("rsvg-convert -w 96 -h 96 %s -o %s" % (file, new)) | |
print file + " Complete" |
This file contains hidden or 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 | |
""" | |
@file android-iconify_launcher.py | |
@license GPLv3 | |
@author [email protected] | |
@date copyright 2018 | |
@brief Automate the re-sizing of icons for Android using python and ImageMagick based on Michael Mitchell python script | |
@usage android-iconify.py icon_file_to_convert.svg | |
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] | |
filename = os.path.splitext(sys.argv[1])[0] | |
if file.endswith('.svg'): | |
# 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) | |
newdir = ('./res/drawable-xxxhdpi') | |
if not os.path.exists(newdir): | |
os.mkdir(newdir) | |
newdir = ('./res/googleplaystore') | |
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_' + filename + ".png") | |
os.system ("rsvg-convert -w 12 -h 12 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 48 -h 48 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 72 -h 72 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 96 -h 96 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 144 -h 144 %s -o %s" % (file, new)) | |
# drawable-xxxhdpi | |
new = ('./res/drawable-xxxhdpi/ic_' + filename + ".png") | |
os.system ("rsvg-convert -w 192 -h 192 %s -o %s" % (file, new)) | |
# drawable-googleplaystore | |
new = ('./res/googleplaystore/ic_' + filename + ".png") | |
os.system ("rsvg-convert -w 512 -h 512 %s -o %s" % (file, new)) | |
print file + " Complete" | |
This file contains hidden or 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 | |
""" | |
@file android_iconify_pref.py | |
@license GPLv3 | |
@author [email protected] | |
@date copyright 2018 | |
@brief Automate the re-sizing of icons for Android using python and rsvg-convert based on Michael Mitchell python script | |
@usage android-iconify.py icon_file_to_convert.svg | |
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] | |
filename = os.path.splitext(sys.argv[1])[0] | |
if file.endswith('.svg'): | |
# 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) | |
newdir = ('./res/drawable-xxxhdpi') | |
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_' + filename + ".png") | |
os.system ("rsvg-convert -w 12 -h 12 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 16 -h 16 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 24 -h 24 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 32 -h 32 %s -o %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_' + filename + ".png") | |
os.system ("rsvg-convert -w 48 -h 48 %s -o %s" % (file, new)) | |
# drawable-xxxhdpi | |
new = ('./res/drawable-xxxhdpi/ic_' + filename + ".png") | |
os.system ("rsvg-convert -w 64 -h 64 %s -o %s" % (file, new)) | |
print file + " Complete" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment