Created
November 17, 2025 02:45
-
-
Save khlam/b4b86627e19d8a53189318ff956122f1 to your computer and use it in GitHub Desktop.
Deterministic SHA-256 hash from the image RGB data.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pathlib import Path | |
| import hashlib | |
| from PIL import Image | |
| def _image_rgb_hash(path: Path) -> str: | |
| """Compute a deterministic SHA-256 hash from the image RGB data.""" | |
| with Image.open(path) as img: | |
| rgb_img = img.convert("RGB") | |
| pixel_bytes = rgb_img.tobytes() | |
| h = hashlib.sha256() | |
| h.update(pixel_bytes) | |
| return h.hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment