Forked from tomvon/resize-image-keep-aspect-ratio.py
Created
September 24, 2020 18:55
-
-
Save saxenanurag/0402165a329293ec3bbcc8f7fce2ad7d to your computer and use it in GitHub Desktop.
Python script to resize an image while keeping the original aspect ratio.
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
#Resizes an image and keeps aspect ratio. Set mywidth to the desired with in pixels. | |
import PIL | |
from PIL import Image | |
mywidth = 300 | |
img = Image.open('someimage.jpg') | |
wpercent = (mywidth/float(img.size[0])) | |
hsize = int((float(img.size[1])*float(wpercent))) | |
img = img.resize((mywidth,hsize), PIL.Image.ANTIALIAS) | |
img.save('resized.jpg') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment