-
-
Save sany2k8/d358c5988f43e4c1eb25e9779d5bae88 to your computer and use it in GitHub Desktop.
Resize image with Python
This file contains hidden or 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
# Require PIL (Python Imaging Library) | |
import traceback, Image | |
def resize(): | |
filePath = 'example.jpg' | |
ratio = 0.5 | |
image = Image.open(filePath) | |
width = image.size[0] | |
height = image.size[1] | |
newWidth = int(round(width * ratio)) | |
newHeight = int(round(height * ratio)) | |
newImage = image.resize((newWidth, newHeight), Image.ANTIALIAS) | |
newImage.format = image.format | |
newImage.save(filePath) | |
if __name__ == '__main__': | |
try: | |
resize() | |
except Exception as e: | |
traceback.print_exc(e) | |
raw_input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment