Skip to content

Thumbhash implementation in PHP real Object

Notifications You must be signed in to change notification settings

jerrywham/thumbhash

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thumbhash PHP

Tests Latest Stable Version

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

Read more and test it here !

Installation

You can install Thumbhash PHP using Composer:

composer require jerrywham/thumbhash

⚠️ I higly recommand to have Imagick extension installed on your computer. GD extension has only 7 bits of alpha channel resolution, and 127 is transparent, 0 opaque. While the library will still work, you may have different image between platforms. See on stackoverflow

Usage

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;

$Th = new Thumbhash($url);

$thumbBase64 = rtrim(base64_encode(implode(array_map("chr", $Th->getHash() ))), '=');
$data_url = $Th->toDataURL($Th->getHash() );

echo '<img style="width: 200px; height: auto; border: 1px solid black;" width="'. $Th->getWidth() .'" height="'. $Th->getHeight() .'" src="'. $data_url .'" alt="">';

Credits

Thumbhash PHP was created by Eser DENIZ. Modify by Cyril MAGUIRE.

It is inspired by the javascript version of Evan Wallace's Thumbhash algorithm.

License

Thumbhash PHP is licensed under the MIT License. See LICENSE for more information.

About

Thumbhash implementation in PHP real Object

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%