Advertisement
here2share

# delete_imageIDtag.py

Aug 8th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # the line above needs to be at top of the python file, otherwise an error may result about encoding
  3. # delete_imageIDtags.py
  4.  
  5. from PIL import Image
  6. import os
  7. import sys
  8. import string
  9.  
  10. # cmdargs = sys.argv[0]
  11. # dir = '/'.join(cmdargs.split('\\')[:-1])
  12. Dir = 'C:/images/temp/'
  13. fileID = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY'
  14. zzz='ZZZ/'
  15. if not os.path.exists(dir+zzz): os.makedirs(dir+zzz)
  16.  
  17. for file_name in os.listdir(dir):
  18.     new_file_name = ''.join(c for c in file_name if c in string.printable)
  19.     os.rename(os.path.join(dir,file_name), os.path.join(dir, new_file_name))
  20.  
  21. filenames = []
  22. for f in os.listdir(dir.decode('utf8')):
  23.     filenames.append(f)
  24. # filenames = os.listdir(dir) ### as copied, it had caused non-ascii conficts
  25. for filename in filenames:
  26.     if filename.endswith((".jpg", ".jpeg")):
  27.         target = (r"%s/%s" % (dir, filename)).replace('//','/')
  28.         try:
  29.             image = Image.open(target)
  30.             try:
  31.                 data = list(image.getdata())
  32.                 image_without_exif = Image.new(image.mode, image.size)
  33.                 image_without_exif.putdata(data)
  34.                 tack = list(set(data[len(data)/2:]))[0:8] ### ZZZ next to catch by 80:1 ratio
  35.                 for i in range(len(tack)):
  36.                     tmp = tack[i]
  37.                     tack[i] = fileID[(tmp[0]*(256**2)+tmp[1]*256+tmp[2])%len(fileID)]
  38.                 tack=''.join(tack)
  39.                 xy = image.size
  40.                 xx,yy=str(xy[0]).zfill(4),str(xy[1]).zfill(4)
  41.                 tack = '%sz%sz%s.jpg' % (yy,xx,tack)
  42.             except:
  43.                 tack = "Z_"+filename.split('.')[0]
  44.             newName = dir+zzz+tack
  45.             while newName in os.listdir(dir+zzz):
  46.                 tack = '_'+tack
  47.                 newName = dir+zzz+tack
  48.             image_without_exif.save(newName)
  49.             #print ("[OK] %s" % tack)
  50.         except: print '!!! Error: Unable To Fully Access --', target
  51. #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement