A new algorithm achieves unprecedented compression for image previews, encoding any image into just 16 bytes while maintaining fast decoding speeds and cross-language compatibility.
When developers need to show image previews before full downloads, they've traditionally faced a trade-off between file size and quality. Enter SplatHash, a new algorithm that compresses any image to exactly 16 bytes—a 22-character base64url string—while reconstructing a 32×32 blurry preview in just 0.067 milliseconds.
![]()
Breaking the Size Barrier
The compression achievement is remarkable: while competitors like ThumbHash require 25-37 bytes and BlurHash uses 20-25 bytes, SplatHash achieves its results with a fixed 16-byte output. This consistency matters for systems that need predictable storage and bandwidth usage.
The algorithm works by encoding a background color plus six Gaussian blobs positioned through matching pursuit, with colors optimized using Ridge Regression in the Oklab color space. The entire model packs into 128 bits, making it storable as a 128-bit integer—something neither ThumbHash nor BlurHash can claim.
Performance That Scales
Benchmarks on an Intel Core i5-9300H reveal the practical advantages:
- Decoding: 0.067 ms (SplatHash) vs 0.50 ms (ThumbHash) vs 6.55 ms (BlurHash)
- Encoding: 3.53 ms (SplatHash) vs 0.86 ms (ThumbHash) vs 445 ms (BlurHash)
- Memory allocations: 7 (SplatHash) vs 1,168 (ThumbHash) vs 5 (BlurHash)
This performance profile reflects thoughtful optimization: decoding runs on every page load for every user, while encoding happens once at upload. SplatHash prioritizes decode speed, achieving a 7.5x improvement over ThumbHash and a 98x improvement over BlurHash.
Cross-Language Consistency
Perhaps most impressively, SplatHash guarantees bit-exact parity across implementations. Go serves as the reference implementation, with TypeScript/JavaScript and Python versions verified to produce identical hashes. This eliminates the subtle bugs that plague cross-platform image processing libraries.
Feature Comparison
| Feature | SplatHash | ThumbHash | BlurHash |
|---|---|---|---|
| Fixed output size | Yes (16 bytes) | No | No |
| Storable as 128-bit integer | Yes | No | No |
| Perceptual color space (Oklab) | Yes | No | No |
| Spatially localized basis | Yes (Gaussians) | No | No |
| Global weight optimization | Yes (Ridge) | No | No |
| Alpha channel support | Yes | Yes | No |
| Bit-exact cross-language parity | Yes | No | No |
| Configurable quality vs. size | No | No | Yes |
Practical Applications
The fixed 16-byte size makes SplatHash ideal for systems with strict storage constraints. Social media platforms, image galleries, and any application showing progressive image loading can benefit from the predictable footprint and blazing-fast decoding.
The inclusion of alpha channel support and Oklab color space provides better perceptual accuracy than competitors, while the spatially localized Gaussian basis produces more natural-looking previews than global basis functions.
Getting Started
SplatHash is available for Go, TypeScript/JavaScript, and Python:
- Go:
go get github.com/junevm/splathash/src/go - TypeScript/JavaScript:
npm install splathash-ts - Python:
pip install splathash-py
Development requires mise for consistent environment setup, with commands for testing (mise run test), benchmarking (mise run bench), and regenerating comparison images (mise run compare).
The algorithm represents a significant advance in the niche but important field of image preview compression, achieving smaller sizes, faster decoding, and better cross-platform consistency than existing solutions.
Comments
Please log in or register to join the discussion