loveduckie/silverstripe-webp-image
Composer 安装命令:
composer require loveduckie/silverstripe-webp-image
包简介
Automatically generate and serve .webp images from existing .jpeg, .png, and .gif files.
关键字:
README 文档
README
silverstripe-webp-image
Overview
The silverstripe-webp-image module enhances your SilverStripe website's performance by automatically converting image assets to the efficient .webp format on demand. Learn more about WebP's benefits here. For additional details and insights, check out Tips for Optimizing Page Speeds.
Thanks
Thanks to nomidi/silverstripe-webp-image for developing the original version of this extension.
I've since forked it and modified it to use Imagick, added support for .gif, and made other optimizations.
Features
- ✅ Automatically generates
.webpversions of resized JPEG, PNG, and GIF images. - ✅ Significantly improves page load times with minimal configuration, making it SEO friendly.
- ✅ Designed for seamless integration with NGINX.
- ✅ Native support for Imagick.
How does it work?
Resized or altered versions of image assets are stored to disk for caching and optimization purposes. This extension intercepts calls for retrieving these cached and resized assets by automatically generating .webp counterparts of the same images. This usually occurs when leveraging Silverstripe's image manipulation features via its templating engine.
Afterwards, and depending on your server's configuration, NGINX will attempt to serve the .webp version of your resized image asset instead of the source version. If the .webp version does not exist, then it will instead serve the original version.
This extension provides conversion support for .jpeg, .png, and .gif assets using Imagick.
Requirements
- SilverStripe
>= 4.2 - GD Library with WebP support enabled
- Imagick
Installation
Install the module using Composer:
composer require loveduckie/silverstripe-webp-image
Run the following to initialize:
vendor/bin/sake dev/build flush=1
Web Server Configuration
This module creates .webp images with filenames structured as file_name.<original_extension>.webp. To serve WebP images when supported, configure your web server as follows:
NGINX Configuration
Add the following to your NGINX configuration:
map $http_accept $webp_suffix { default ""; "~*webp" ".webp"; } location ~* /assets/.+\.(?<extension>jpe?g|png|gif|webp)$ { gzip_static on; gzip_types image/png image/x-icon image/webp image/svg+xml image/jpeg image/gif; add_header Vary Accept; expires max; sendfile on; try_files "${request_uri}${webp_suffix}" $uri =404; }
This setup detects browsers that support WebP via the Accept header and serves the .webp version if available.
Apache .htaccess Configuration
For Apache users, add rules to prioritize .webp files in your .htaccess. For detailed instructions, see CSS-Tricks' guide.
Testing WebP Support
To verify WebP support in your environment, create a .php file with the following content and open it in your browser:
<?php if (function_exists('imagewebp')) { echo "WebP is available"; } else { echo "WebP is not available"; }
Browser Support and Fallbacks
For browsers that don't support WebP, ensure your HTML or server configuration serves alternative formats like JPEG or PNG. Learn more about graceful degradation strategies on CSS-Tricks.
Roadmap
- Enhanced documentation
Imagick support- PHP tests to validate WebP compatibility
- Automatic cleanup of unused
.webpfiles - Command-line functionality for flushing
.webpfiles
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests to improve the module.
loveduckie/silverstripe-webp-image 适用场景与选型建议
loveduckie/silverstripe-webp-image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 660 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「silverstripe」 「Webp」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 loveduckie/silverstripe-webp-image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 loveduckie/silverstripe-webp-image 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 loveduckie/silverstripe-webp-image 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Replace image URLs found in HTML
Webp converter scenarios
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Generate responsive Wordpress images. Supports .webp, lazyload, bootstrap.
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
Image optimization widget for Yii2 Framework with auto WebP/AVIF image format generation from PNG/JPG files.
统计信息
- 总下载量: 660
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2022-03-04