cubic/wn-imageresizer-plugin
Composer 安装命令:
composer require cubic/wn-imageresizer-plugin
包简介
Winter CMS Plugin to resize and compress images.
README 文档
README
- Introduction
- Available filters
- Using a string
- Using a variable
- resize()
- imageWidth() - imageHeight()
- Image Compression
Introduction
Resizes an image to the required dimensions. It accepts a string with a file path to the image or a Winter\Storm\Database\Attach\File object (you will have one of these if you have used the attachOne or AttachMany relationship)
Please note, the not found image can be overwritten via the settings in the admin area.
Available filters
resize(int $width [, int $height , array $options]), imageWidth(), imageHeight()
Using a string
Please note, if the filter alters the URL, you must apply resize afterwards
{{ 'assets/graphics/background.jpg' | theme | resize(500,500) }}
Using a variable
{{ property.image | resize(500) }}
resize(int $width [, int $height , array $options])
Resize an image according to the given params. If $width or $height is 0, that value is calculated using original image ratio
Options
| Key | Description | Default | Options |
|---|---|---|---|
| mode | How the image should be fitted to dimensions | auto | exact, portrait, landscape, auto, fit or crop |
| offset | Offset the resized image | [0,0] | [int, int] |
| extension | The extension on the image to return | auto | auto, jpg, jpeg, gif, png |
| quality | The quality of compression *requires cache clear | 95 | 0-100 |
| sharpen | Sharpen the image across a scale of 0 - 100 *requires cache clear | 0 | 0-100 |
| compress | Whether the image should be compressed or not. Only takes effect when TinyPng compression is enabled. | true | true,false |
Usage in template
{{ property.image | resize(500, false, { mode: 'crop', quality: '80', extension: 'png' }) }}
Usage in PHP
The image resizer can also be used easily in PHP, as follows:
use Cubic\ImageResizer\Classes\Image;
$image = new Image('/path/to/image.jpg');
$image->resize(150, 200, [ 'mode' => 'crop' ]);
Usage in Backend List
The image resizer can also be used on backend lists with the type of thumb, e.g.
image:
label: Image
type: thumb
This works with:
You can also optionally pass width (default 50), height (default 50) and options as follows:
image:
label: Image
type: thumb
width: 75
height: 100
options:
mode: crop
imageWidth() - imageHeight()
Return current image width/height - useful if you need to know the size of an image resized only by one side.
{{ '/path/to/image.jpg' | resize(250) | imageHeight() }}
Image Compression via TinyPNG
The plugin integrates with the TinyPNG API to provide image compression. A developer API key is required, to obtain one visit https://tinypng.com/developers. Once obtained, enter it in the Image Resizer Settings area of October CMS backend.
TinyPNG offer 500 free compression per month, the plugin automatically caches resized images to save credits, an option to not compress certain images is also available.
If you are focussed on pagespeed, it is recommended to set your image quality at 70-80 to obtain the lowest filesize whilst still retaining high quality images.
cubic/wn-imageresizer-plugin 适用场景与选型建议
cubic/wn-imageresizer-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 cubic/wn-imageresizer-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cubic/wn-imageresizer-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-04