Skip to content

Instantly share code, notes, and snippets.

@junaidk
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junaidk/9623275 to your computer and use it in GitHub Desktop.
Save junaidk/9623275 to your computer and use it in GitHub Desktop.
create all sizes of icon for android application from a given image
# 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