Skip to content

Instantly share code, notes, and snippets.

@pdxjohnny
Last active August 29, 2015 14:13
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 pdxjohnny/1dedcba9becd68859170 to your computer and use it in GitHub Desktop.
Save pdxjohnny/1dedcba9becd68859170 to your computer and use it in GitHub Desktop.
Resizes images to whatever sizes are listed in the resize_config.txt file, great for creating iPhone icons
#! /usr/bin/python
from PIL import Image
import sys
import os
imageFile = sys.argv[1]
file_name = imageFile.split(".")[0]
ext = imageFile.split(".")[-1]
sizes = []
with open("resize_config.txt","r") as config_file:
for line in config_file:
sizes.append( line.split(" x ").replace( "\r", "" ).replace( "\n", "" ) )
im1 = Image.open(imageFile)
if not os.path.isdir( file_name ):
os.mkdir( file_name )
for resize in sizes:
temp = im1.resize(( int(resize[0]) , int(resize[1]) ), Image.ANTIALIAS)
temp.save( file_name + "/" + resize[0] + "x" + resize[1] + "." + ext )
180 x 180
120 x 120
152 x 152
76 x 76
1024 x 1024
640 x 1136
640 x 960
1536 x 2048
2048 x 1536
768 x 1024
1024 x 768
120 x 120
80 x 80
40 x 40
87 x 87
58 x 58
58 x 58
58 x 58
29 x 29
66 x 66
44 x 44
22 x 22
75 x 75
50 x 50
50 x 50
50 x 50
25 x 25
180 x 180
120 x 120
120 x 120
152 x 152
76 x 76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment