fundevogel / kirby3-colorist
Kirby v3的colorist包装器
Requires
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14
- phpunit/phpunit: ^8.1
README
这是一个Kirby v3的colorist
包装器。
是什么
这个库作为替代的缩略图驱动器,完全遵循Darkroom
规范。因此,kirby3-colorist
不会与自定义的thumb()
方法(与其他插件一起提供)冲突,同时与流行的'Focus'插件完全兼容。
它是Joe Drago的colorist
的Kirby v3包装器。虽然它能够生成和操作下一代图像格式(无限制 - AVIF - 强大!),但某些功能不受支持(如应用blur
或grayscale
)。
从colorist的README
Colorist是一个图像文件和ICC配置文件转换器、生成器和标识符。为什么需要这样一个工具,当尊贵的ImageMagick已经存在并且似乎提供你所能想象到的所有可能的图像处理工具时?答案是绝对亮度。
如果这听起来很有趣,并且你想继续阅读,请务必查看其命令行或访问主页获取更多信息。
如何
使用Composer安装此包
composer require fundevogel/kirby3-colorist
现在,启用插件
// config.php return [ // .. 'thumbs.driver' => 'colorist', ];
注意:如果您只想生成类似webp
的内容,则无需这样做,因为gd
和im
可以轻松处理它。使用toFormat('webp')
不需要将colorist
选为thumb.driver
(见下文)。
用法
此插件公开了几个方法和配置选项。
例如,如果您想将图像转换为另一种格式
// Converting a single image to single format: $image = $page->image('example.jpg'); $webp = $image->toFormat('webp'); // Since this method return a `$file` object, chaining works as usual $thumb = $webp->thumb('some-preset'); // Converting a single image to multiple formats: $image = $page->image('example.jpg'); $results = $image->toFormats(['png', 'webp']);
为了方便,还有针对多个图像的方法
// Converting multiple images to single format: $images = $page->images(); $webps = $images->toFormat('webp'); // Converting multiple images to multiple formats: $images = $page->images(); $results = $images->toFormats(['png', 'webp']);
您还可以提取图像配置文件信息,例如
$image = $page->image('example.jpg'); $profile = $image->identify();
有关更多详细信息,请参阅以下部分。
配置
您还可以从全局的config.php
更改某些选项,例如:'fundevogel.colorist.optionName'
(或简单地将其传递给thumb()
方法)
插件选项
基本选项
输入配置文件选项
输出配置文件选项
输出格式选项
注意:当与多个格式一起工作时,您可能希望将thumbs.quality
转换为数组
// config.php return [ // .. 'thumbs.quality' => [ 'avif' => 60, 'webp' => 80, ], ]; // template.php $image->toFormat('avif')->thumb(['width' => 300]);
注意:您还可以为每个格式定义文件模板
// config.php return [ // .. 'fundevogel.colorist.template' => [ 'avif' => 'early-bird', 'webp' => 'google-lover', ], ];
方法
目前,以下方法可用
identify (bool $asArray)
提供有关图像颜色配置文件(主色、亮度等)以及宽度、高度和深度的信息。
toFormat (string $format = 'avif')
将图像转换为$format
,并将其放置在相应的content
文件夹中与原始版本相邻。它返回一个$file
对象,可通过thumb()
等方法使用。
toFormats (array $formats)
将图像转换为多个$formats
,并将其放置在相应的content
文件夹中与原始版本相邻。它返回一个$files
对象。
hasFormat (string $format)
检查文件 $file
是否包含指定格式的图像,返回 bool
。
isFormat (字符串 $format)
检查文件 $file
是否为指定格式的图像,返回 bool
。
钩子
在图像上传时,文件会自动转换为 'fundevogel.colorist.formats'
选项中的所有格式(默认为 ['webp']
)。
标签
支持在编辑器中直接使用 (colorist: example.jpg)
标签进行转换/调整大小。
选项
进行中
路线图
colorist
库提供更多功能,更多选项将陆续开放 - 如果您觉得缺少某些功能,请随时提交 PR!
- 添加测试
-
为文件上传/更新添加钩子 -
为编辑器添加标签 -
添加与 @flokosiol 的 'Focus' 插件的兼容性 - 添加编辑 ICC 颜色配置文件的方法
致谢
致谢应该给予,作为 colorist
的创作者,Joe Drago 是当之无愧的人选。他提供的二进制文件推动了这个项目,我对他出色的贡献表示感谢。
此外,我还要感谢 @flokosiol 和 @hashandsalt,我从他们的工作中学习(并借用)了一些东西。
祝您编码愉快!
©️ Fundevogel Kinder- und Jugendbuchhandlung