Skip to content

Commit

Permalink
Merge pull request #96 from ral-facilities/DSEGOG-298-Backend-Create-…
Browse files Browse the repository at this point in the history
…image-hashing-script-for-phash

Replace hashlib.md5 with imagehash.phash in util script
  • Loading branch information
patrick-austin authored Mar 4, 2024
2 parents 8572af0 + 228fefa commit 9e04efd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/ci_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ auth:
private_key_path: /home/runner/work/operationsgateway-api/id_rsa
public_key_path: /home/runner/work/operationsgateway-api/id_rsa.pub
jwt_algorithm: RS256
access_token_validity_mins: 120
access_token_validity_mins: 180
refresh_token_validity_days: 7
fedid_server_url: ldap://fed.cclrc.ac.uk:389
fedid_server_ldap_realm: FED.CCLRC.AC.UK
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import argparse
import base64
import hashlib
import io

import imagehash
from PIL import Image

"""
This script is used to generate MD5 checksums, used to assert thumbnails in tests
This script is used to generate perceptual hashes, used to assert thumbnails in tests
"""

parser = argparse.ArgumentParser()
Expand All @@ -20,6 +23,7 @@
BASE64_THUMBNAIL = args.thumbnail

bytes_thumbnail = base64.b64decode(BASE64_THUMBNAIL)
md5_checksum = hashlib.md5(bytes_thumbnail).hexdigest()
image = Image.open(io.BytesIO(bytes_thumbnail))
phash = imagehash.phash(image)

print(f"MD5 Checksum: {md5_checksum}")
print(f"Perceptual hash: {phash}")

0 comments on commit 9e04efd

Please sign in to comment.