nelson / resizer
此包的最新版本(8.2.0)没有可用的许可证信息。
Nette 框架与 Latte 的 Resizer 扩展
8.2.0
2023-06-26 12:09 UTC
Requires
- php: ^8.1
- ext-fileinfo: *
- imagine/imagine: ^1.3.3
- latte/latte: ^2.11.0 || ^3.0.0
- nette/application: ^3.1
- nette/di: ^3.0
- nette/http: ^3.1
- nette/schema: ^1.0
- nette/utils: ^3.2 || ^4.0
Requires (Dev)
- phpstan/extension-installer: ^1.0
- phpstan/phpstan: ^1.0.0
- phpstan/phpstan-nette: ^1.0.0
- phpunit/phpunit: ^9.0.0
- roave/security-advisories: dev-master
- tracy/tracy: ^2.9
This package is auto-updated.
Last update: 2024-09-30 01:30:41 UTC
README
-
Composer:
composer require nelson/resizer -
注册
extensions: resizer: Nelson\Resizer\DI\ResizerExtension
-
配置
这是所需的最小配置
resizer: library: 'Imagick' # Imagick|Gmagick|Gd wwwDir: %wwwDir% tempDir: %tempDir%
其他选项及其默认值
resizer: interlace: true # for progressive JPEGs strip: true # removes image metadata, color profiles etc. cache: '/resizer/' qualityAvif: 70 # 0 - 100 qualityWebp: 70 # 0 - 100 qualityJpeg: 70 # 0 - 100 compressionPng: 9 # 0 - 9 upgradeJpg2Webp: true # automatically convert JPEGs to WEBP when the format is supported by the browser & server upgradeJpg2Avif: true # automatically convert JPEGs to AVIF when the format is supported by the browser & server upgradePng2Webp: true # automatically convert PNGs to WEBP when the format is supported by the browser & server upgradePng2Avif: true # automatically convert PNGs to AVIF when the format is supported by the browser & server
还提供了 AVIF & WEBP 的升级/降级逻辑。首选的是原始的 AVIF/WEBP,然后是其他格式,最后是 JPEG。
如果同时启用了升级,则优先使用 AVIF 而不是 WEBP。
用法
参数顺序取决于路由器,默认为
- 尺寸和修饰符。
string - 图像文件。
string - 格式。
string
尺寸和修饰符
语法:- [ifresize-][[cropX]width]x[[cropY]height][forceDimensions][-quality]
尺寸
100x100- 宽度和高度必须相等或更小,按 AR 缩放。x100- 高度必须相等或更小。100x- 宽度必须相等或更小。100x50!- 强制尺寸而不尊重 ifresize 和 AR。- 裁剪
- 宽度:
l- 左,c- 中,r- 右。 - 高度:
t- 上,c- 中,b- 下。 - 示例:
c100xc100
- 宽度:
修饰符
ifresize- 示例:
ifresize-100x200 - 如果图像的宽度或高度小于期望值,则不会放大图像。
- 示例:
- 质量
- 示例:
x-q50- 仅设置质量而不进行任何缩放。 - 对于 WEBP/AVIF,质量设置为
100表示无损压缩。
- 示例:
格式
- 可以使用格式参数在图像文件格式之间切换,例如在
<picture>标签中使用<source srcset="">将 jpeg 转换为 WEBP/AVIF。
相对和绝对 URL
相对
<img src="{rlink 'test.jpg', '200x100'}">
绝对,使用不同的标签
<img src="{rlinkabs 'test.jpg', 'l400xc200'}"><a href="{rlinkabs 'test.jpg', 'l400xc200'}" target="_blank">图片链接</a>