kwaadpepper/image-resizer

实时调整图片大小并缓存

3.0.2 2024-06-21 17:48 UTC

This package is auto-updated.

Last update: 2024-09-21 18:29:09 UTC


README

Latest Version on Packagist Total Downloads Build Status StyleCI

实时调整图片大小并返回新的链接

安装

通过 Composer

composer require kwaadpepper/image-resizer

用法

1 - 发布配置

php artisan vendor:publish --provider="Kwaadpepper\ImageResizer\ImageResizerServiceProvider"

2 - 在模板数组中设置配置(config/image-resizer.php)

/**
 *   resize => will resize the image (boolean)
 *   fit => Combine cropping and resizing to format image in a smart way (boolean)
 *   keepRatio => will keep image ratio wile resizing (boolean)
 *   trim => boolean to trim the image using border color
 *   inCanvas => to make sure image boundarie is respected
 *   format => select tha wantd ouput form, yan can just convert images if you want
 */
'templates' => [
    'smallWebp' => [
        'height' => 500,
        'width' => 250,
        'inCanvas' => true,
        'format' => 'webp',
        'trim' => ['transparent', null, 10]
    ]
]

3 - 在控制台输入 php artisan storage:link

4 - 在您的 blade 模板中覆盖图片链接

<img src="{{ asset(resize('images/volaillesfr_landing.png', 'smallWebp')) }}" alt="My resized image">

5 - 可选:您可以使用命令 php artisan image-resizer:clean-cache 手动清理过时的缓存文件,或者使用 php artisan cache:clean 强制清理缓存

  • 请注意,在生产环境中,它将自动每半小时调度一次

变更日志

请参阅 变更日志 了解最近的变化信息。

测试

composer test

贡献

请参阅 contributing.md 了解详细信息及待办事项列表。

安全

如果您发现任何安全问题,请通过电子邮件 github@jeremydev.ovh 反馈,而不是使用问题跟踪器。

鸣谢

许可证

MIT。请参阅 许可证文件 了解更多信息。