Skip to content

Instantly share code, notes, and snippets.

@mascot6699
Created July 29, 2015 18:34
Show Gist options
  • Save mascot6699/70bcad0858f9ea0dab9a to your computer and use it in GitHub Desktop.
Save mascot6699/70bcad0858f9ea0dab9a to your computer and use it in GitHub Desktop.
from PIL import Image
import pdb
BANNER_SIZE = (650,400)
THUMBNAIL_SIZE = (106,80)
TILE_SIZE = (82,61)
GIVEN_FILE = "tile123.png"
def resize_picture(saved_name, root_image, size):
im = Image.open(root_image)
x,y = im.size
X,Y = size
if x >= X and y >= Y:
try:
image_banner = open(saved_name, 'w')
except IOError as e:
print "I/O error({0}): {1}".format(e.errno, e.strerror)
im_banner = im.resize(size)
im_banner.save(image_banner)
print "success"
else:
print "Upload a image with size more than that of {0}".format(size)
resize_picture("banner123.png", GIVEN_FILE, BANNER_SIZE)
resize_picture("thumbnail123.png", GIVEN_FILE, THUMBNAIL_SIZE)
resize_picture("tile123.png", GIVEN_FILE, TILE_SIZE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment