Skip to content

Instantly share code, notes, and snippets.

@wichopy
Last active February 10, 2017 22:15
Show Gist options
  • Save wichopy/df3762376df9d870f05ef2a9fc913b4d to your computer and use it in GitHub Desktop.
Save wichopy/df3762376df9d870f05ef2a9fc913b4d to your computer and use it in GitHub Desktop.
Scan a folder and reduce and jpgs larger then 3 MB to 1024x786 resolution.
from PIL import Image
from resizeimage import resizeimage
import os
dir = 'C:\Users\chouw\Documents\pictures'
for dirname,subdirlist,flist in os.walk(dir):
for fname in flist:
if fname.lower().endswith('.jpg'):
if os.stat(dir+"\\"+fname).st_size > 3000:
print "resize {}".format(fname),
with open(dir+"\\"+fname, 'r+b') as f:
with Image.open(f) as image:
red_img = resizeimage.resize_contain(image, [1024, 768])
red_img.save('1024x768'+fname, image.format)
print "done resizing... now moving..."
os.rename(os.path.join(os.getcwd(),'1024x768'+fname), os.path.join(os.getcwd()+"\\Reduced Pictures",'1024x768'+fname))
print "done resizing and moving... closing now"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment