arnoson/kirby-auto-srcset

自动生成图像 srcset

安装: 93

依赖: 0

建议者: 0

安全: 0

星标: 4

关注者: 3

分支: 1

开放问题: 0

类型:kirby-plugin

v2.0.0 2022-09-30 09:21 UTC

This package is auto-updated.

Last update: 2024-08-30 21:02:33 UTC


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,
    // ...
  ],
];