定制 chromos33/silverstripe-webp-image 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chromos33/silverstripe-webp-image

最新稳定版本:0.1

Composer 安装命令:

composer require chromos33/silverstripe-webp-image

包简介

Automatically generate and serve .webp images from existing .jpeg, .png, and .gif files.

README 文档

README

silverstripe-webp-image

Build Status License

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 .webp versions 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 .webp files
  • Command-line functionality for flushing .webp files

Contributing

Contributions are welcome! Please feel free to submit issues or pull requests to improve the module.

统计信息

  • 总下载量: 49
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2025-11-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固