Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
resize images for Android
import os
import glob
from PIL import Image
from math import ceil
for asset in glob.glob('drawable-xhdpi/*png'):
img =
xhdpi = img.size
hdpi = [ceil(xhdpi2hdpi*x) for x in xhdpi]
mdpi = [ceil(hdpi2mdpi*x) for x in hdpi]
ldpi = [ceil(mdpi2ldpi*x) for x in mdpi]
for convert_factor,dir_name in [(hdpi,'hdpi'),(mdpi,'mdpi'),(ldpi,'ldpi')]:
os.system("convert -resize %dx%d %s drawable-%s/%s" % \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment