Encode an identifier into an image's pixels; verify a JSON record against any copy
Project description
Mememage
Encode an identifier into an image's pixels; verify a JSON record against any copy.
Mememage writes a 2-pixel-tall bar into the bottom rows of an image. The bar holds two values:
- identifier — a short string that points to a JSON record, stored separately (a server, a CDN, IPFS, a file).
- content hash — a 64-bit digest (the first 16 hex of SHA-256) over the record.
verifyrecomputes it and compares against the bar.
What's tamper-evident: the record. Change any field and verify fails. Two keys sit outside the hash by design — signature, so a detached signature can attach later without re-hashing, and _-prefixed keys, reserved as unhashed scratch for decoders (encode refuses both as your field names). Core proves the record-to-image binding — it does not police the pixels (edit the image but leave the bar, and it still verifies) and does not prove authorship (that's a signature's job, out of core's scope).
The bar survives JPEG, resaves, screenshots, and re-uploads, so the identifier reads back from a shared copy.
Downscaling is the limit. A modest shrink is safe: images ≥ ~1000px wide decode after a resize to 0.8× plus one recompression — 59 of 60 real-image round-trips, across three resamplers and JPEG q70–q80. Beyond that we make no promise. Whether a smaller copy still decodes depends on the image, the resampler, and whether it was recompressed; half-size copies of large images often decode, and aggressive downscales sometimes do too, but not dependably enough to rely on. Images already under ~1000px wide use a denser bar layout and aren't promised any downscale. encode reads any image Pillow can open and writes a lossless PNG; decode and verify work on any format the bar survives. Record fields are arbitrary — captions, credits, generation parameters, links — apart from a few names reserved for the format itself (identifier, content_hash, hash_version, signature, encrypted_fields).
pip install mememage # encode / decode / verify — Pillow included
# pip install "mememage[encrypt]" # adds AES-256 field encryption
Quickstart
Three functions, all pure image operations:
import mememage
# encode — write the bar into the image, build the record from your fields
result = mememage.encode("photo.png", {"title": "Morning fog", "by": "catmemes"})
result.identifier # 'mememage-3dc5f03a747bb38e' (derived from the fields)
result.save("photo.json") # the record — store or serve it separately
# decode — read the bar back out of the pixels (the inverse of encode)
bar = mememage.decode("photo.jpg") # any format the bar survived: PNG, JPEG, a screenshot
bar.identifier, bar.content_hash
# verify — does a record match an image? (recomputed hash == the bar's)
mememage.verify("photo.jpg", result.record) # True if the record is intact
You resolve the record from its identifier — look it up wherever you keep it, then verify:
bar = mememage.decode("photo.jpg") # identifier + content hash from the pixels
record = my_store[bar.identifier] # your storage: a dict, a file, a DB, a URL
mememage.verify("photo.jpg", record) # True if the record matches the image
encodeaccepts any image — a path,bytes, a file-like, a PILImage, or a numpy array (HEIC needs the[heic]extra) — and returns the barred image asRecord.image. Given a destination — a path (in place, or a.pngsibling for non-PNG),out=<path.png>, orout=<stream>(e.g.BytesIO) — it writes the file. Output is always PNG: the bar is lossless, and a lossy re-encode would corrupt it. An in-memory input with no destination never touches disk.decode/verifyaccept the same in-memory forms — a path,bytes, a file-like, a PILImage, or a numpy array. No disk round-trip.- No network I/O —
decodereturns the identifier; you resolve the record. Core is pure pixel + hash operations.
Encrypt private fields
- Mark fields
privateto encrypt them (AES-256-GCM via PBKDF2) under a password. - The record still verifies without the password — the hash covers the ciphertext.
unlockreturns the decrypted fields. The password is not stored; only the ciphertext is kept in the record.
result = mememage.encode("photo.png", {"title": "Public", "gps": "45.5,-122.6"},
password="hunter2", private=["gps"])
mememage.verify("photo.png", result.record) # matches — no password
mememage.unlock(result, "hunter2")["gps"] # '45.5,-122.6'
Command line
mememage encode photo.png --field title="Morning fog" -o photo.json # write the record
mememage decode photo.jpg --record photo.json # VERIFIED (exit 0) / RECORD ALTERED (exit 1)
mememage decode photo.jpg # read the identifier only (no record)
Without -o, the record is written next to the image as <identifier>.json.
With --record, decode exits 0 on a match and 1 on a mismatch; without it,
exit 0 just means a bar was read.
License
MIT.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mememage-0.1.4.tar.gz.
File metadata
- Download URL: mememage-0.1.4.tar.gz
- Upload date:
- Size: 52.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e672ca3e7899c68a3fbd7355fbe02f9ad14c1c314842d91f9eb152870695db3
|
|
| MD5 |
d1eb3c278185c008d211b25e22bbe613
|
|
| BLAKE2b-256 |
730eff5dbc26ca8809a38649922c3d0ceaefbf55f8c572e5d2812168a060291d
|
Provenance
The following attestation bundles were made for mememage-0.1.4.tar.gz:
Publisher:
publish.yml on sememtac/mememage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mememage-0.1.4.tar.gz -
Subject digest:
5e672ca3e7899c68a3fbd7355fbe02f9ad14c1c314842d91f9eb152870695db3 - Sigstore transparency entry: 2135010831
- Sigstore integration time:
-
Permalink:
sememtac/mememage@4570347b718ec10f2a9a5e57fd2eb7f8959a2f80 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/sememtac
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4570347b718ec10f2a9a5e57fd2eb7f8959a2f80 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mememage-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mememage-0.1.4-py3-none-any.whl
- Upload date:
- Size: 38.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dd62b366437dc8dfdf77a4b7fa9a7178b5539d002061679e851beba9720685f
|
|
| MD5 |
0b36b7ed626e277fe63b03448de33176
|
|
| BLAKE2b-256 |
cbad4bfa7bd51b322398ef69bfad9c388f46793128efa18f72430cb399859ced
|
Provenance
The following attestation bundles were made for mememage-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on sememtac/mememage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mememage-0.1.4-py3-none-any.whl -
Subject digest:
3dd62b366437dc8dfdf77a4b7fa9a7178b5539d002061679e851beba9720685f - Sigstore transparency entry: 2135010844
- Sigstore integration time:
-
Permalink:
sememtac/mememage@4570347b718ec10f2a9a5e57fd2eb7f8959a2f80 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/sememtac
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4570347b718ec10f2a9a5e57fd2eb7f8959a2f80 -
Trigger Event:
release
-
Statement type: