定制 srwiez/thumbhash 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

srwiez/thumbhash

最新稳定版本:v1.5.0

Composer 安装命令:

composer require srwiez/thumbhash

包简介

A brief description of your package

README 文档

README

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 srwiez/thumbhash

⚠️ I highly recommend 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;

$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 . '" />';

Note

Like the original library implementation, your image must not exceed 100x100 pixels.

Credits

Thumbhash PHP was created by Eser DENIZ.

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.

统计信息

  • 总下载量: 89.12k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 159
  • 点击次数: 1
  • 依赖项目数: 9
  • 推荐数: 2

GitHub 信息

  • Stars: 159
  • Watchers: 3
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-23