JohannesBuchner / imagehash

A Python Perceptual Image Hashing Module
BSD 2-Clause "Simplified" License
3.14k stars 328 forks source link

Error when trying to get hash-value with imagehash? #175

Closed Rapid1898-code closed 2 years ago

Rapid1898-code commented 2 years ago

i try to the hash-value for an image using imagehash with this code:

from PIL import Image
import imagehash
import requests
img = "https://cdn1.bitchesgirls.com/file/yael1c-yael-cohen-aug-31-2022/261656199427347453059782996929595436595.jpg"
# img = "https://i.imgur.com/5bGzZi7.jpg"
resp = requests.get(img, stream=True)
ihashImg = imagehash.average_hash(Image.open(resp.raw)) 
print(ihashImg)

When i try to run this code i get this error:

$ python test1.py
Traceback (most recent call last):
  File "C:\Users\Polzi\Documents\DEV\Fiverr\TRY\pilom1\test1.py", line 7, in <module>
    ihashImg = imagehash.average_hash(Image.open(resp.raw))
  File "C:\Users\Polzi\Documents\DEV\.venv\test\lib\site-packages\PIL\Image.py", line 3147, in open
    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x000002128FEA6860>

Why is this (for at least some pics) not working?

Eg. this picture works without problems: https://i.imgur.com/5bGzZi7.jpg

JohannesBuchner commented 2 years ago

is the code working without imagehash?

from PIL import Image
import imagehash
import requests
img = "https://cdn1.bitchesgirls.com/file/yael1c-yael-cohen-aug-31-2022/261656199427347453059782996929595436595.jpg"
# img = "https://i.imgur.com/5bGzZi7.jpg"
resp = requests.get(img, stream=True)
img = Image.open(resp.raw)
print(img)
Rapid1898-code commented 2 years ago

Hello - i also get the error without imagehash...

JohannesBuchner commented 2 years ago

Closing, as not a imagehash issue. In the future, please avoid NSFW demos if possible.