goimagehash/hashImage/hashImage.py

28 lines
589 B
Python
Raw Normal View History

2024-05-01 17:59:11 -07:00
from __future__ import annotations
import argparse
import imagehash
from PIL import Image
def bin_str(hash):
return ''.join(str(b) for b in 1 * hash.hash.flatten())
def main(args: list[str] | None = None) -> str:
ap = argparse.ArgumentParser()
ap.add_argument('-file', required=True)
opts = ap.parse_args(args)
im = Image.open(opts.file)
return (
f'ahash: {bin_str(imagehash.average_hash(im))}\n'
f'dhash: {bin_str(imagehash.dhash(im))}\n'
f'phash: {bin_str(imagehash.phash(im))}'
)
if __name__ == '__main__':
print(main())