承接 octfx/webp 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

octfx/webp

Composer 安装命令:

composer require octfx/webp

包简介

Generate WebP Versions of images

README 文档

README

Upon file upload this extension creates a WebP (and Avif if active) version of the uploaded image and its thumbs.

Requires a working job queue, Extension:PictureHtmlSupport, and a usable version of imagick, libwebp (cwebp), or gd installed.
As well as $wgHashedUploadDirectory = true;, and if Extension:AWS is active $wgAWSRepoHashLevels to be >0;

Setting $wgGenerateThumbnailOnParse = false; is currently not supported.

How does this work?

After an upload or file transformation, a transform job is dispatched that creates a webp (and avif if active) file version of the original file.

Additionally, the PictureHtmlSupport extension exposes a hook when a thumbnail is added to the page output.
Extension:WebP utilizes this hook to add a <source> element for each active image transformer.

Converting already uploaded images

A maintenance script exists to convert already uploaded images:

php extensions/WebP/maintenance/CreateFromLocalFiles.php

# To only convert non-thumbnails run
php extensions/WebP/maintenance/CreateFromLocalFiles.php --no-thumbs

# To create thumbnails of custom sizes run
# This will create two thumbnails with size 1000px and 1250px
php extensions/WebP/maintenance/CreateFromLocalFiles.php --thumb-sizes=1000,1250

# To only work on some images run
php extensions/WebP/maintenance/CreateFromLocalFiles.php --titles=ImageA.jpg,ImageB.png

# To force the creation of already existing images run
php extensions/WebP/maintenance/CreateFromLocalFiles.php --overwrite

# Only work on page titles matching a prefix
# Every page starting with prefix 'Example' will be selected
php extensions/WebP/maintenance/CreateFromLocalFiles.php --title-prefix=Example

# Only work on page titles matching a file-type
# Every page starting with file-type 'png' will be selected
# Can be combined with 'title-prefix'
php extensions/WebP/maintenance/CreateFromLocalFiles.php --file-type=png

Installation

wfLoadExtension( 'WebP' );

Configuration

Key Description Example Default
$wgWebPEnableConvertOnUpload Enables file creation after a new image was uploaded. Doesn't work for copy uploads. true true
$wgWebPEnableConvertOnTransform Enables file creation after a thumbnail was created. This isn't necessary if a thumbhandler is active. false true
$wgWebPEnableResponsiveVersionJobs Dispatch transform jobs for 1.5x and 2x file versions. Note: This runs for each thumbnail inclusion and may be disabled after all present thumbnails have been converted. false true
$wgWebPCheckAcceptHeader Check if the accept header contains webp. If not the original file will be served. true false
$wgWebPCompressionQuality Compression Quality. Lower means worse. 50 75
$wgWebPCompressionQualityAvif Compression Quality for Avif files. Lower means worse. 50 30
$wgWebPFilterStrength Alpha compression strength. Sets imagick webp:alpha-quality and cwebp -alpha_q. Lossless is 100. 50 80
$wgWebPAutoFilter Enables the auto filter. This algorithm will spend additional time optimizing the filtering strength to reach a well-balanced quality. false true
$wgWebPThumbSizes Thumbnail Sizes to create through the maintenance script [2400] [120, 320, 800, 1200, 1600]
$wgEnabledTransformers List of enabled image transformers [ "MediaWiki\Extension\WebP\Transformer\AvifTransformer", "MediaWiki\Extension\WebP\Transformer\WebPTransformer" ] WebP Transformer
$wgWebPCWebPLocation Path to cwebp executable /usr/bin/cwebp
$wgWebPAvifencLocation Path to avifenc executable /usr/bin/avifenc

Enabling Avif

For full feature support you'll need to install Imagick v7, als v6.9 has multiple bugs.
Alternatively you can install libavif-bin (>= 0.9.3) which provides avifenc. Do note that this still requires a version of imagick installed, as avifenc can't rescale images.

When enabling the Avif transformer, make sure that it is ordered before the webp transformer, as else the browser will pick the webp version.

$wgEnabledTransformers = [ "MediaWiki\\Extension\\WebP\\Transformer\\AvifTransformer", "MediaWiki\\Extension\\WebP\\Transformer\\WebPTransformer" ];

De-Installation

Delete the folders images/webp and images/thumbs/webp and remove the extension.
If the Avif transformer is active remove images/avif and images/thumbs/avif.

octfx/webp 适用场景与选型建议

octfx/webp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.34k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2023 年 07 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 octfx/webp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 octfx/webp 我们能提供哪些服务?
定制开发 / 二次开发

基于 octfx/webp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.34k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2023-07-31