blue-tomato / image-blurhash
此包已被废弃,不再维护。没有建议的替代包。
ProcessWire 的模块,用于自动生成 Blurhash
2.0.7
2021-06-27 11:18 UTC
Requires
- php: >=7.0
- ext-curl: *
- ext-exif: *
- ext-gd: *
- composer/installers: ~1.0
- kornrunner/blurhash: ~1.2.1
README
ImageBlurhash 是 ProcessWire CMS 的模块,可自动为上传的图片生成 Blurhash 字符串。
什么是 Blurhash?
BlurHash 是图像占位符的紧凑表示。例如,用于懒加载占位符。
关于 Blurhash 的更多信息
使用方法
安装
- 在 ProcessWire 安装根目录中执行以下命令
composer require blue-tomato/image-blurhash
- ProcessWire 将检测模块并在后端的
模块
>站点
>ImageBlurhash
部分列出。转到那里并安装它。
配置
在图像字段的设置字段中激活 Blurhash: 设置
> 字段
> image_field
> 详情
> 生成 Blurhash 字符串
API
$page->image_field->blurhash
返回编码的 Blurhash 字符串或不存在时返回 false
$page->image_field->getBlurhashDataUri(float $width, float $height)
例如。
<img src="$page->image_field->getBlurhashDataUri(500, 300)" alt="" data-lazy="$page->image_field->size(500, 300)" />
返回解码的 Blurhash 作为 base64 PNG datauri,用于图像。如果不存在,则返回透明的 GIF 图像。
提示:如果您的图像是 500x300 像素,您可以使用 50x30 像素的 Blurhash 数据-URI,并使用 CSS 缩放图像。这使得 Blurhash 解码更快,数据-uri 更小,但质量仍然很好。
现有图像迁移
对于现有字段的迁移,模块目录中有两个 CLI 脚本
regenerateImages.php
例如。
php regenerateImages.php
为具有 createBlurhash 选项的所有图像字段生成新的 Blurhash。
generateEmptyImages.php
例如。
php generateEmptyImages.php
为具有 createBlurhash 选项且数据库中没有 Blurhash 的所有图像字段生成新的 Blurhash。
路线图
目前编码组件质量默认为 4x3。在未来,此值将可通过每个字段的设置进行配置。
支持
请 创建一个问题 以获取支持。
贡献
在你的分支上创建一个分支,将提交添加到你的分支中,并从你的分支向此存储库发起拉取请求。
为了获取更深入的见解并了解模块实现细节,请打开一个支持问题。我们将尽快回复您。
许可证
在LICENCE.txt文件中找到有关本模块许可证的所有信息。