Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- # the line above needs to be at top of the python file, otherwise an error may result about encoding
- # delete_imageIDtags.py
- from PIL import Image
- import os
- import sys
- import string
- # cmdargs = sys.argv[0]
- # dir = '/'.join(cmdargs.split('\\')[:-1])
- Dir = 'C:/images/temp/'
- fileID = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY'
- zzz='ZZZ/'
- if not os.path.exists(dir+zzz): os.makedirs(dir+zzz)
- for file_name in os.listdir(dir):
- new_file_name = ''.join(c for c in file_name if c in string.printable)
- os.rename(os.path.join(dir,file_name), os.path.join(dir, new_file_name))
- filenames = []
- for f in os.listdir(dir.decode('utf8')):
- filenames.append(f)
- # filenames = os.listdir(dir) ### as copied, it had caused non-ascii conficts
- for filename in filenames:
- if filename.endswith((".jpg", ".jpeg")):
- target = (r"%s/%s" % (dir, filename)).replace('//','/')
- try:
- image = Image.open(target)
- try:
- data = list(image.getdata())
- image_without_exif = Image.new(image.mode, image.size)
- image_without_exif.putdata(data)
- tack = list(set(data[len(data)/2:]))[0:8] ### ZZZ next to catch by 80:1 ratio
- for i in range(len(tack)):
- tmp = tack[i]
- tack[i] = fileID[(tmp[0]*(256**2)+tmp[1]*256+tmp[2])%len(fileID)]
- tack=''.join(tack)
- xy = image.size
- xx,yy=str(xy[0]).zfill(4),str(xy[1]).zfill(4)
- tack = '%sz%sz%s.jpg' % (yy,xx,tack)
- except:
- tack = "Z_"+filename.split('.')[0]
- newName = dir+zzz+tack
- while newName in os.listdir(dir+zzz):
- tack = '_'+tack
- newName = dir+zzz+tack
- image_without_exif.save(newName)
- #print ("[OK] %s" % tack)
- except: print '!!! Error: Unable To Fully Access --', target
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement