Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
Convert images to different mobile devices screen sizes
#!/usr/bin/env python
from os import path, makedirs
from glob import glob
from PIL import Image
## list of folders to create
folders = [r'3.5-Inch', r'4-Inch' ,r'4.7-Inch', r'5.5-Inch', r'iPad']
## create folders
for f in folders:
if not path.exists(f):
## list of desired portrait sizes, must match the folders list.
vsizes = [[640, 920], [640, 1096], [750, 1334], [1242, 2208], [768, 1024]]
## search for a jpg file in the root folder
for f in glob('*.jpg'):
im =
for s in vsizes:
size = s[0], s[1]
sizeText = folders[vsizes.index(s)]
im_resized = im.resize(size, Image.ANTIALIAS)'%s\p_%s' % (sizeText, f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment