Last active
August 29, 2015 14:05
-
-
Save siddharth96/758c7baf33ebc513d491 to your computer and use it in GitHub Desktop.
Python script to create image thumbnails while preserving Aspect ratio
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
import PIL | |
from os import listdir | |
from os.path import isfile, join | |
from PIL import Image | |
directory_path = "<some directory>" | |
onlyfiles = [ f for f in listdir(directory_path) if isfile(join(directory_path,f)) ] | |
basewidth = 64 | |
for fl_name in onlyfiles: | |
if not fl_name or fl_name.endswith('.db'): | |
continue | |
img = Image.open(fl_name) | |
wpercent = (basewidth/float(img.size[0])) | |
hsize = int((float(img.size[1])*float(wpercent))) | |
img = img.resize((basewidth,hsize), PIL.Image.ANTIALIAS) | |
img.save(fl_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment