Skip to content

Instantly share code, notes, and snippets.

@eladc
Last active August 29, 2015 14:17
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 eladc/39025ccf7d909f9c467f to your computer and use it in GitHub Desktop.
Save eladc/39025ccf7d909f9c467f to your computer and use it in GitHub Desktop.
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):
makedirs(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 = Image.open(f)
for s in vsizes:
size = s[0], s[1]
sizeText = folders[vsizes.index(s)]
im_resized = im.resize(size, Image.ANTIALIAS)
im_resized.save(r'%s\p_%s' % (sizeText, f))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment