Last active
August 29, 2015 14:11
-
-
Save CrowderSoup/29a93b6798b056f6c8dd to your computer and use it in GitHub Desktop.
Just a quick example of how to resize an INCREDIBLY large image.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Pillow |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment