Skip to content

Instantly share code, notes, and snippets.

@d7my11
Created June 22, 2015 16:25
Show Gist options
  • Save d7my11/f6ec354f5acabe3ea243 to your computer and use it in GitHub Desktop.
Save d7my11/f6ec354f5acabe3ea243 to your computer and use it in GitHub Desktop.
from PIL import Image
if self.thumbnail:
try:
image = Image.open(self.thumbnail.path)
(width, height) = image.size
"Max width and height 800"
if (700 / width < 471 / height):
factor = 471 / height
else:
factor = 700 / width
size = (width / factor, height / factor)
image = image.resize(size, Image.ANTIALIAS)
image.save(self.thumbnail.path)
except Exception:
# TODO log
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment