Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # img_1280ht_aspect_ratio.py
- from PIL import Image
- import re, os, sys
- SIZE = 1280,1280
- fromDir=r"C:\Users\here2share\myImages\Over 1280ht"
- def pf(*z): return '\\'.join(z)
- toDir=pf(fromDir,"Resized to 1280ht")
- if not os.path.exists(toDir): os.makedirs(toDir)
- skipped=pf(fromDir,"---")
- if not os.path.exists(skipped): os.makedirs(skipped)
- def resize_image(f):
- if not os.path.exists(pf(toDir,f)):
- try:
- img = Image.open(pf(fromDir, f))
- if max(img.size) > 1280:
- img.thumbnail(SIZE, Image.ANTIALIAS)
- img.save(pf(toDir, f))
- print '#',
- except:
- # Note: shutil.copy will remove metadata in the process meanwhile shutil.copy2 will not do so
- try: shutil.copy(pf(fromDir, f), pf(skipped, f))
- except: pass
- print '>',
- else:
- print '.',
- for f in os.listdir(fromDir): resize_image(f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement