mrfd/kirby-webp
Composer 安装命令:
composer require mrfd/kirby-webp
包简介
Kirby 3 plugin for converting images to WebP on the fly, with support for file methods and Kirby tags!
README 文档
README
Important
This plugin is no longer actively maintained, as WebP can now be generated natively in Kirby 4.
This plugin for Kirby 3 provides automatic WebP conversion when uploading images (JPG and PNG) via the Panel. With provisions for the use of field methods, KirbyTags and multi-language sites.
Note: When using the field methods and KirbyTags the WebP image will be automatically generated when missing. In addition the WebP image will also be removed when the original image is removed via the Panel.
Commerical Usage
This plugin is free but if you use it in a commercial project please consider to
Requirements
- PHP 7.3+
- Kirby 3
Installation
Download
Download and copy the files to /site/plugins/kirby-webp.
Git submodule
$ git submodule add https://github.com/MRFD/kirby-webp.git site/plugins/kirby-webp
Composer
composer require MRFD/kirby-webp
Usage
Field methods
$field->picture()
Converts the field to a picture tag with WebP and fallback for unsupported browsers.
<?php if ($image = $page->image('my-image.jpg')) { echo $image->picture('some-class', 'Image description'); } ?>
<picture class="some-class"> <source srcset="/your/path/my-image.webp" type="image/webp" /> <img src="/your/path/my-image.jpg" alt="Image description" /> </picture>
$field->webp()
Converts the field to a WebP image tag.
<?php if ($image = $page->image('my-image.jpg')) { echo $image->webp('some-class', 'Image description', [300, 800, 1024]); } ?>
<img src="/your/path/my-image.webp" srcset=" /your/path/my-image-300.webp 300w, /your/path/my-image-800.webp 800w, /your/path/my-image-1024.webp 1024w " class="some-class" alt="Image description" /> <!-- Or when the browser does not support WebP: --> <img src="/your/path/my-image.jpg" srcset=" /your/path/my-image-300.jpg 300w, /your/path/my-image-800.jpg 800w, /your/path/my-image-1024.jpg 1024w " class="some-class" alt="Image description" />
All arguments are optional.
It is also possible to use the predefined srcset. For the default option use: $image->webp('some-class', 'Image description', 'default').
$field->isSupported()
Validates the WebP format is supported by the visitor's browser.
<?php $image = $page->image('my-image.jpg'); if ($image->isSupported()) { echo "Browser supports WebP! :)"; } else { echo "Browser doesn't support WebP."; } ?>
$field->backgroundImage()
Returns an image url that can be used with inline CSS, for example with background images. Based on the visitor's browser the url provides a regular or WebP format.
<?php if ($image = $page->image('my-image.jpg')) : ?> <div style="background-image: url('<?= $image->backgroundImage() ?>')"></div> <?php endif ?>
<div style="background-image: url('/your/path/my-image.webp')"></div> <!-- Or when the browser does not support WebP: --> <div style="background-image: url('/your/path/my-image.jpg')"></div>
KirbyTags
Picture tag
Creates an picture tag with fallback for unsupported browsers.
(picture: myawesomepicture.jpg)
(picture: myawesomepicture.jpg class: floated)
(picture: myawesomepicture.jpg alt: This is an awesome picture)
<picture class="some-class"> <source srcset="/your/path/my-image.webp" type="image/webp" /> <img src="/your/path/my-image.jpg" alt="Image description" /> </picture>
Image tag
Creates an image tag with WebP file. Can be a regular image, or a WebP format.
(webp: myawesomepicture.jpg)
(webp: myawesomepicture.jpg class: floated)
(webp: myawesomepicture.jpg alt: This is an awesome picture)
<img src="/your/path/my-image.webp" class="some-class" alt="Image description" /> <!-- Or when the browser does not support WebP: --> <img src="/your/path/my-image.jpg" class="some-class" alt="Image description" />
Options
Convert on the fly
It is possible to convert images to WebP without uploading them through the panel. Add the following option to /site/config/config.php:
# site/config/config.php return [ 'mrfd.webp.autoconvert' => true ];
Note: Enabling this option may slow down the website. It is therefore advised to upload the images via the panel!
Conversion options
For configuring advanced WebP conversion settings. For example:
# site/config/config.php return [ 'mrfd.webp.convert.options' => [ 'metadata' => 'all', 'jpeg' => [ 'converters' => ['cwebp'], ], 'png' => [ 'encoding' => 'auto', 'near-lossless' => 60, 'quality' => 85, ], ], ];
For all possible options, please read this and this.
Disclaimer
This plugin is provided "as is" with no guarantee. Use it at your own risk and always test it yourself before using it in a production environment. If you find any issues, please create a new issue.
License
Kirby WebP is open-sourced software licensed under the MIT license.
Copyright © 2020 Marijn Roovers
Credits
- WebP Convert by @rosell-dk
- Kirby 2 WebP @S1SYPHOS
mrfd/kirby-webp 适用场景与选型建议
mrfd/kirby-webp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.13k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2020 年 04 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「kirby3」 「kirby3-cms」 「kirby3-plugin」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mrfd/kirby-webp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mrfd/kirby-webp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mrfd/kirby-webp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Cache-busting utility to fingerprint assets (JS/CSS) in Kirby 3
Kirby plugin to schedule the automatic publishing of pages on a certain date+time. It is built to work with enabled cache.
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
A image cropping field for kirby.
Retrotree is a kirby 3 section plugin to display pages in real retro tree fashion.
Enable page and file template hooks for Kirby 3
统计信息
- 总下载量: 1.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-23