Skip to content

Instantly share code, notes, and snippets.

@khlam
Created November 17, 2025 02:45
Show Gist options
  • Select an option

  • Save khlam/b4b86627e19d8a53189318ff956122f1 to your computer and use it in GitHub Desktop.

Select an option

Save khlam/b4b86627e19d8a53189318ff956122f1 to your computer and use it in GitHub Desktop.
Deterministic SHA-256 hash from the image RGB data.
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