Created
August 10, 2016 14:17
-
-
Save eiszfuchs/9360a23955db042404db466d394f1ee2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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