Skip to content

Instantly share code, notes, and snippets.

@eiszfuchs
Created August 10, 2016 14:17
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 eiszfuchs/9360a23955db042404db466d394f1ee2 to your computer and use it in GitHub Desktop.
Save eiszfuchs/9360a23955db042404db466d394f1ee2 to your computer and use it in GitHub Desktop.
import hashlib
from wand.image import Image as wand_image
from PIL import Image as pillow_image
# Generate raw-pixels checksums to identify identical images
# ignoring different [JPG] metadata or [PNG] compression
# levels (i.e. binary different).
# Due to the different libraries, these two methods will not
# generate the same checksum for the same file!
def hash_image_wand(filename):
with wand_image(filename=filename) as img:
print(hashlib.sha256(img.make_blob('RGBA')).hexdigest())
def hash_image_pillow(filename):
with pillow_image.open(filename) as img:
print(hashlib.sha256(img.tobytes()).hexdigest())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment