arnoson / kirby-auto-srcset
自动生成图像 srcset
v2.0.0
2022-09-30 09:21 UTC
Requires
README
这是一个为 Kirby 3
生成图像 srcset 的插件。基于 Processwire CMS
用户 DaveP
的论坛 帖子。
安装
composer require arnoson/kirby-auto-srcset
使用方法
$srcset = $image->autoSrcset([ 'minWidth' => 300, 'maxWidth' => 1024, 'thumb' => [ 'format' => 'avif', 'quality' => 80, ], ]);
这将创建最小和最大尺寸,以及介于两者之间的尺寸,尝试以大约 20kb 文件大小步骤创建图像。
配置
所有选项可以直接传递给 $file->autoSrcset()
或者在配置中设置。
// your-template.php $srcset = $image->autoSrcset([ 'minWidth' => 300, 'maxWidth' => 1000, // in kb 'fileSizeStep' => 20, // The maximum number of images to be created. 'maxSteps' => 10, // An optional ratio that is used to crop the image. 'ratio' => 16 / 9, // Options to pass to kirby's `$file->thumb()` method. 'thumb' => [ 'quality' => 80, 'format' => 'jpeg', 'crop' => 'center', // ... ], ]);
// config.php return [ 'arnoson/kirby-auto-srcset' => [ 'minWidth' => 300, 'maxWidth' => 1000, // ... ], ];