commonsmachinery / blockhash-python

Implementation of perceptual image hash calculation in Python
http://blockhash.io/
MIT License
130 stars 29 forks source link

Calculating hash from an image url #7

Closed davegri closed 4 years ago

davegri commented 8 years ago

I noticed that in the JS version there is an option to calculate the hash from a URL, is the possible in python? Right now I'm saving the image to disk and then calculating the hash but It would be nice If I could just calculate it directly form the URL.

patatetom commented 6 years ago

hi davegri,

you can easilly do it under bash/linux with curl :

blockhash.py <( curl -s https://pre00.deviantart.net/d675/th/pre/i/2013/231/9/9/arch_linux_wallpaper_by_wavering_radiant-d6ivbsy.png ) | awk '{print $1}'
3fc03f803fc03f861f063f861f861f0e1f0f160f3e0f301f7e3f3e3f003f0038

or under python3 with :

from urllib.request import urlopen
from io import BytesIO as iobytes
import blockhash
im = blockhash.Image.open(iobytes(urlopen('https://pre00.deviantart.net/d675/th/pre/i/2013/231/9/9/arch_linux_wallpaper_by_wavering_radiant-d6ivbsy.png').read()))
blockhash.blockhash(im, 16)
'3fc03f803fc03f861f063f861f861f0e1f0f160f3e0f301f7e3f3e3f003f0038'

hope it'll help you.

dsoprea commented 4 years ago

It's probably safe to close this issue, now.