Skip to content

Instantly share code, notes, and snippets.

@CrowderSoup
Last active August 29, 2015 14:11
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 CrowderSoup/29a93b6798b056f6c8dd to your computer and use it in GitHub Desktop.
Save CrowderSoup/29a93b6798b056f6c8dd to your computer and use it in GitHub Desktop.
Just a quick example of how to resize an INCREDIBLY large image.
from PIL import Image
# 8 Inches
basewidth = 768
# This is the size of the image I was working with... this line will supress warnings about the image being too big
Image.MAX_IMAGE_PIXELS = 556631040
# Open the image
img = Image.open("original.png")
# Calculate the width % and height size based on the fixed width
# To do fixed height you would simply flip things around
wpercent = (basewidth / float(img.size[0]))
hsize = int((float(img.size[1]) * float(wpercent)))
# Resize the image using anti-aliasing
img = img.resize((basewidth, hsize), Image.ANTIALIAS)
# Save the image
img.save("/Users/acrowder/Desktop/resized.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment