Created
January 26, 2020 19:22
-
-
Save thesaadarshad/282341eb86efc9f9960254997af5faec to your computer and use it in GitHub Desktop.
python image resize with 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
#!/usr/bin/env python | |
import PIL | |
from PIL import Image | |
import os, sys | |
mywidth = 1200 | |
path = "/pathtofolder/" | |
dirs = os.listdir( path ) | |
def resize(): | |
for item in dirs: | |
if os.path.isfile(path+item): | |
img = Image.open(path+item) | |
wpercent = (mywidth/float(img.size[0])) | |
hsize = int((float(img.size[1])*float(wpercent))) | |
img = img.resize((mywidth,hsize), PIL.Image.ANTIALIAS) | |
img.save(path+'resized/'+item) | |
resize() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment