Advertisement
here2share

# img_remove_hidden_data.py

Nov 15th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 KB | None | 0 0
  1. # img_remove_hidden_data.py
  2.  
  3. from PIL import Image
  4. import re, os, sys
  5. import shutil
  6.  
  7. fromDir=r"C:\Users\here2share\New Images"
  8.  
  9. def pf(*z): return '\\'.join(z)
  10.  
  11. toDir=pf(fromDir,"Removed Hidden")
  12. if not os.path.exists(toDir): os.makedirs(toDir)
  13.  
  14. def cleanup_image(f):
  15.     if f.lower().endswith(tuple('.png .bmp .jpg .jpeg'.split())):
  16.         try:
  17.             img = Image.open(pf(fromDir, f))
  18.             img.save(pf(toDir, os.path.splitext(f)[0]+'.jpg'))
  19.             print '#',
  20.         except:
  21.             shutil.copy(pf(fromDir, f), pf(toDir, r'000 '+f))
  22.             print '>',
  23.  
  24. for f in os.listdir(fromDir): cleanup_image(f)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement