Last active
August 29, 2015 13:57
-
-
Save junaidk/9623275 to your computer and use it in GitHub Desktop.
create all sizes of icon for android application from a given image
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
# Uses PIL library for resizing | |
# http://www.pythonware.com/products/pil/ | |
# resize.py arg1 arg2 | |
# arg1 : src image name | |
# arg2 : dir path of src image | |
import os | |
import getopt | |
import sys | |
from PIL import Image | |
image = sys.argv[1] | |
directory = sys.argv[2] | |
out_img = 'ic_launcher.png' | |
print 'image name : ' + image | |
print 'dir name : ' + directory | |
pathArray = ['res\\drawable-ldpi','res\\drawable-mdpi','res\\drawable-hdpi','res\\drawable-xhdpi','res\\drawable-xxhdpi'] | |
sizeArray = [36,48,72,96,144] | |
print '## making directory structure' | |
for path in pathArray: | |
os.makedirs(directory + '\\' + path) | |
print '## directory structure done' | |
# Open the image file. | |
img = Image.open(os.path.join(directory, image)) | |
# Resize it. | |
for i in range(0,5): | |
img1 = img.resize((sizeArray[i],sizeArray[i]), Image.ANTIALIAS) | |
img1.save(os.path.join(directory, pathArray[i] +'\\'+ out_img)) | |
print '# image drawable ' + str(sizeArray[i]) +' x '+ str(sizeArray[i]) | |
print ' --------------- done --------------- ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment