Skip to content

Instantly share code, notes, and snippets.

@llimllib
Created May 7, 2014 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save llimllib/ffbb87e0af9463cef977 to your computer and use it in GitHub Desktop.
Save llimllib/ffbb87e0af9463cef977 to your computer and use it in GitHub Desktop.
from PIL import Image
from glob import glob
import os
# pip install imagehash
import imagehash
images = {}
for f in glob("images/*"):
i = Image.open(f)
if i.size[0] < i.size[1]:
print f
i = i.rotate(90)
i.save(f)
# check for dupe-ish images. 5 is a sensitivity parameter; its value was
# determined empirically.
h = imagehash.average_hash(i, 5).hash.tostring()
if h in images:
print "{} is a dupe of {}? deleting.".format(f, images[h])
os.unlink(f)
else:
images[h] = f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment