Skip to content

Instantly share code, notes, and snippets.

@vadimii
Created February 9, 2014 05:23
Show Gist options
  • Save vadimii/8894694 to your computer and use it in GitHub Desktop.
Save vadimii/8894694 to your computer and use it in GitHub Desktop.
Thumbnail and end up with a square image
from PIL import Image
size = (36, 36)
image = Image.open(data)
image.thumbnail(size, Image.ANTIALIAS)
background = Image.new('RGBA', size, (255, 255, 255, 0))
background.paste(
image,
((size[0] - image.size[0]) / 2, (size[1] - image.size[1]) / 2))
from PIL import Image, ImageOps
thumb = ImageOps.fit(image, size, Image.ANTIALIAS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment