forked from noenfugler/LemmyModBot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathphash_tool.py
More file actions
30 lines (22 loc) · 780 Bytes
/
phash_tool.py
File metadata and controls
30 lines (22 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# A tool that takes in an image and spits out a Phash
import argparse
from io import BytesIO
import requests
from PIL import Image
import imagehash
parser = argparse.ArgumentParser()
parser.add_argument("--file", "-f", dest="file", help="A local file to load and process")
parser.add_argument("--url", "-u", dest="url", help="A remote file to load and process")
def main():
args = parser.parse_args()
if args.file is None and args.url is None:
print("Must set either input file or url!")
return
img = None
if args.file is not None:
img = Image.open(args.file)
elif args.url is not None:
img = Image.open(BytesIO(requests.get(args.url).content))
print(str(imagehash.phash(img)))
if __name__ == "__main__":
main()