Guest User

Untitled

a guest
Apr 25th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. import os
  2. import sys
  3. from PIL import Image
  4.  
  5. args = sys.argv[1:]
  6.  
  7. rs = int(args[args.index("-r") + 1]) if "-r" in args else 2
  8. gr = args[args.index("-g") + 1] if "-g" in args else "r"
  9. dn = args[args.index("-d") + 1] if "-d" in args else "resize"
  10.  
  11. files = os.listdir(os.getcwd())
  12. if dn not in files:
  13. os.mkdir(dn)
  14.  
  15. imgs = [f for f in files if ".jpg" in f]
  16.  
  17. for im in imgs:
  18. img = Image.open(im)
  19. name, ext = os.path.splitext(im)
  20. width, height = img.size
  21.  
  22. rimg = img.resize((width//rs, height//rs))
  23. rimg.save(f"./{dn}/{name}_{gr}{ext}", quality=75)
Add Comment
Please, Sign In to add comment