Thumbhash PHP is a PHP library for generating unique, human-readable identifiers from image files. It is inspired by Evan Wallace's Thumbhash algorithm and provides a PHP implementation of the algorithm.
Thumbhash is a very compact representation of a placeholder for an image. Store it inline with your data and show it while the real image is loading for a smoother loading experience. It's similar to BlurHash but with some advantages
You can install Thumbhash PHP using Composer:
composer require srwiez/thumbhash
To generate a thumbhash for an image file, you can use the Thumbhash\Thumbhash class:
Example to show a thumbhash image from a local file
use Thumbhash\Thumbhash;
$content = file_get_contents($url);
list($width, $height, $pixels) = extract_size_and_pixels_with_imagick($content);
$hash = Thumbhash::RGBAToHash($width, $height, $pixels);
$key = Thumbhash::convertHashToString($hash); // You can store this in your database as a string
$url = Thumbhash::toDataURL($hash);
echo '<img src="' . $url . '" />';
Thumbhash PHP was created by Eser DENIZ.
It is inspired by the javascript version of Evan Wallace's Thumbhash algorithm.
Thumbhash PHP is licensed under the MIT License. See LICENSE for more information.