eislambey / splathash-php
16 bytes fixed size image placeholder, an alternative to blurhash and thumbhash
1.0.0
2026-05-01 18:54 UTC
Requires
- php: >=8.2
- ext-gd: *
Requires (Dev)
- phpunit/phpunit: ^12
This package is auto-updated.
Last update: 2026-05-01 18:57:36 UTC
README
PHP port of SplatHash: compress any image to exactly 16 bytes and reconstruct a 32x32 RGBA placeholder.
Requirements
- PHP 8.2+
ext-gdforSplatHash::encode()from image files orGdImage
Install
composer require eislambey/splathash-php
Usage
<?php use Islambey\SplathashPhp\SplatHash; require __DIR__ . '/vendor/autoload.php'; $hash = SplatHash::encode('photo.jpg'); // 16 raw bytes $string = SplatHash::toBase64Url($hash); // 22-char base64url string $sameHash = SplatHash::fromBase64Url($string); $rgba = SplatHash::decode($sameHash); // 32 * 32 * 4 raw RGBA bytes
For already decoded pixels:
$hash = SplatHash::encodeRaw($rgbaBytes, $width, $height);
API
SplatHash::encode(string|GdImage $source): stringSplatHash::encodeRaw(string $rgba, int $width, int $height): stringSplatHash::decode(string $hash): stringSplatHash::toBase64Url(string $hash): stringSplatHash::fromBase64Url(string $value): string
Development
composer install php tests/run.php
License
MIT