SplatHash: compress any image to 16 bytes and reconstruct it
Project description
SplatHash — Python
Python implementation of SplatHash: compress any image to 16 bytes and reconstruct it.
Requirements
- Python 3.8+
- Pillow (for loading image files)
Installation
pip install splathash-py
For local development from the repo:
pip install -e src/py
Usage
from splathash import encode, encode_raw, decode
# Encode from a file path
with open("photo.jpg", "rb") as f:
hash_bytes = encode(f) # bytes, always 16 bytes
# Or from a file path string directly
hash_bytes = encode("photo.jpg")
# Or from a PIL Image
from PIL import Image
img = Image.open("photo.jpg")
hash_bytes = encode(img)
# Encode from raw RGBA bytes
hash_bytes = encode_raw(rgba_bytes, width, height)
# Decode to 32×32 RGBA
pixels = decode(hash_bytes) # bytes, 32 * 32 * 4 = 4096 bytes
See example.py for a full working example that encodes a directory of images.
API
encode(source) -> bytes
Encodes an image to a 16-byte SplatHash.
source can be:
- A file path (
strorPath) - A file-like object (binary mode)
- A
PIL.Image.Image
Returns bytes of exactly 16 bytes.
encode_raw(rgba: bytes, width: int, height: int) -> bytes
Encodes raw RGBA pixel data. rgba must be width * height * 4 bytes.
Returns bytes of exactly 16 bytes.
decode(hash_bytes: bytes) -> bytes
Decodes a 16-byte SplatHash to a 32×32 RGBA image.
Returns bytes of exactly 32 * 32 * 4 = 4096 bytes (raw RGBA, row-major).
Raises ValueError if hash_bytes is not exactly 16 bytes.
Converting the decoded bytes to an image
from PIL import Image
from splathash import encode, decode
hash_bytes = encode("photo.jpg")
pixels = decode(hash_bytes)
img = Image.frombytes("RGBA", (32, 32), pixels)
img.save("preview.png")
Testing
pip install pytest Pillow
pytest test_splathash.py -v
Or via mise from the repo root:
mise run test:py
How It Works
See ALGORITHM.md for the full technical specification.
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 splathash_py-1.3.0.tar.gz.
File metadata
- Download URL: splathash_py-1.3.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eec5a695cd8ad6525fb091bc365e45198d04307ac65632aec9254af2448e30e7
|
|
| MD5 |
d46e369e66deb202ce0fb408862aa5f6
|
|
| BLAKE2b-256 |
2b9dec7c71eb141c13639c1478001fefffc8e842d94e593543daf88a9494e4ea
|
Provenance
The following attestation bundles were made for splathash_py-1.3.0.tar.gz:
Publisher:
release.yml on junevm/splathash
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
splathash_py-1.3.0.tar.gz -
Subject digest:
eec5a695cd8ad6525fb091bc365e45198d04307ac65632aec9254af2448e30e7 - Sigstore transparency entry: 1004806563
- Sigstore integration time:
-
Permalink:
junevm/splathash@01f4bd0143639a2eba44b7e7912b4f1be13aae2f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/junevm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@01f4bd0143639a2eba44b7e7912b4f1be13aae2f -
Trigger Event:
push
-
Statement type:
File details
Details for the file splathash_py-1.3.0-py3-none-any.whl.
File metadata
- Download URL: splathash_py-1.3.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c5d31a9744b4756c60d0177051485996c4e625edd6338d5705d69444538b851
|
|
| MD5 |
c2c6f5011c0433faa9e11c69bfbf50b8
|
|
| BLAKE2b-256 |
68ba4e69a326c0daf38940451afc4b7c6f750f49936c8477d3189253faea0e7c
|
Provenance
The following attestation bundles were made for splathash_py-1.3.0-py3-none-any.whl:
Publisher:
release.yml on junevm/splathash
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
splathash_py-1.3.0-py3-none-any.whl -
Subject digest:
8c5d31a9744b4756c60d0177051485996c4e625edd6338d5705d69444538b851 - Sigstore transparency entry: 1004806564
- Sigstore integration time:
-
Permalink:
junevm/splathash@01f4bd0143639a2eba44b7e7912b4f1be13aae2f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/junevm
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@01f4bd0143639a2eba44b7e7912b4f1be13aae2f -
Trigger Event:
push
-
Statement type: