Created
January 3, 2015 09:25
-
-
Save jossef/60ace700ac81c45ca30a to your computer and use it in GitHub Desktop.
python jpg thumbnail creator
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 os | |
from PIL import Image | |
output_dir = '.\\output' | |
thumbnail_size = (200,200) | |
if not os.path.exists(output_dir): | |
os.makedirs(output_dir) | |
for dirpath, dnames, fnames in os.walk(".\\input"): | |
for f in fnames: | |
full_path = os.path.join(dirpath, f) | |
if f.endswith(".jpg"): | |
filename = 'thumbnail_{0}'.format(f) | |
new_path = os.path.join(output_dir, filename) | |
if os.path.exists(new_path): | |
os.remove(new_path) | |
im = Image.open(full_path) | |
im.thumbnail(thumbnail_size) | |
im.save(new_path, "JPEG") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment