百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
W

webp-convert

> 编程语言
开源

使用 PHP 将 jpeg/png 转换为 webp (如果可能的话)

603 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用 PHP 将 jpeg/png 转换为 webp (如果可能的话)

WebP Convert

Convert JPEG & PNG to WebP with PHP

This library enables you to do webp conversion with PHP. It supports an abundance of methods for converting and automatically selects the most capable of these that is available on the system.

The library can convert using the following methods:

  • cwebp (executing cwebp binary using an exec call)
  • vips (using Vips PHP extension)
  • imagick (using Imagick PHP extension)
  • gmagick (using Gmagick PHP extension)
  • imagemagick (executing imagemagick binary using an exec call)
  • graphicsmagick (executing graphicsmagick binary using an exec call)
  • ffmpeg (executing ffmpeg binary using an exec call)
  • wpc (using WebPConvert Cloud Service - an open source webp converter for PHP - based on this library)
  • ewwww (using the ewww cloud converter (1 USD startup and then free webp conversion))
  • gd (using the Gd PHP extension)

In addition to converting, the library also has a method for serving converted images, and we have instructions here on how to set up a solution for automatically serving webp images to browsers that supports webp.

Installation

Require the library with Composer, like this:

composer require rosell-dk/webp-convert

Converting images

Here is a minimal example of converting using the WebPConvert::convert method:

php
// Initialise your autoloader (this example is using Composer)
require 'vendor/autoload.php';

use WebPConvert\WebPConvert;

$source = __DIR__ . '/logo.jpg';
$destination = $source . '.webp';
$options = [];
WebPConvert::convert($source, $destination, $options);

The WebPConvert::convert method comes with a bunch of options. The following introduction is a must-read: docs/v2.0/converting/introduction-for-converting.md.

If you are migrating from 1.3.9, read this

Serving converted images

The WebPConvert::serveConverted method tries to serve a converted image. If there already is an image at the destination, it will take that, unless the original is newer or smaller. If the method cannot serve a converted image, it will serve original image, a 404, or whatever the 'fail' option is set to. It also adds X-WebP-Convert-Log headers, which provides insight into what happened.

Example (version 2.0):

…

The following introduction is a must-read (for 2.0): docs/v2.0/serving/introduction-for-serving.md.

The old introduction (for 1.3.9) is available here: docs/v1.3/serving/convert-and-serve.md

WebP on demand

The library can be used to create a WebP On Demand solution, which automatically serves WebP images instead of jpeg/pngs for browsers that supports WebP. To set this up, follow what's described in this tutorial (not updated for 2.0 yet).

Projects using WebP Convert

CMS plugins using WebP Convert

This library is used as the engine to provide webp conversions to a handful of platforms. Hopefully this list will be growing over time. Currently there are plugins / extensions / modules / whatever the term is for the following CMS'es (ordered by market share):

  • Wordpress
  • Drupal 7
  • Contao
  • Kirby
  • October CMS

Other projects using WebP Convert

  • webp-convert-cloud-service A cloud service based on WebPConvert

  • webp-convert-concat The webp-convert library and its dependents as a single PHP file (or two)

Supporting WebP Convert

Bread on the table don't come for free, even though this library does, and always will. I enjoy developing this, and supporting you guys, but I kind of need the bread too. Please make it possible for me to have both:

  • Become a backer or sponsor on Patreon.
  • Buy me a Coffee

Supporters

Persons currently backing the project via patreon - Thanks!

  • Max Kreminsky
  • Nodeflame
  • Mathieu Gollain-Dupont
  • Ruben Solvang

Persons who recently contributed with ko-fi - Thanks!

  • 18 Oct: Magestyx
  • 10 Oct: Jesper
  • 4 Oct: Caio Nogueira
  • 22 Sep: Mark
  • 8 Sep: Brinsley
  • 4 Aug: Henri
  • 13 Jun: Pat
  • 2 May: Label Vier
  • 28 Apr: Nealboy
  • 11 Apr: Anonymous
  • 3 Apr: Jakub
  • 28 Mar: ciriman
  • 31 Jan: Aron

Persons who contributed with extra generously amounts of coffee / lifetime backing (>50$) - thanks!:

  • Max Kreminsky ($115)
  • Justin - BigScoots ($105)
  • Bill Vallance ($102)
  • Label Vier ($100)
  • Sebastian ($99)
  • Tammy Lee ($90)
  • Steven Sullivan ($51)
  • Mathieu Gollain-Dupont ($50)
  • Erica Dreisbach ($50)
  • Brian Laursen ($50)
  • Dimitris Vayenas ($50)

New in 2.9.0 (released 7 dec 2021, on my daughters 10 years birthday!)

  • When exec() is unavailable, alternatives are now tried (emulations with proc_open(), passthru() etc). Using this library to do it.
  • Gd is now marked as not operational when the needed functions for converting palette images to RGB is missing. Rationale: A half-working converter causes more trouble than one that is marked as not operational
  • Improved CI tests. It is now tested on Windows, Mac and with deactivated functions (such as when exec() is disabled)
  • And more (view closed issues here

New in 2.8.0:

  • Converter option definitions are now accessible along with suggested UI and helptexts. This allows one to auto-generate a frontend based on conversion options. The feature is already in use in the webp-convert file manager, which is used in WebP Express. New method: WebPConvert::getConverterOptionDefinitions()
  • The part of the log that displays the options are made more readable. It also now warns about deprecated options.
  • Bumped image-mime-type guesser library to 0.4. This version is able to dectect more mime types by sniffing the first couple of bytes.
  • And more (view closed issues here

New in 2.7.0:

  • ImageMagick now supports the "near-lossless" option (provided Imagick >= 7.0.10-54) #299
  • Added "try-common-system-paths" option for ImageMagick (default: true). So ImageMagick will now peek for "convert" in common system paths #293
  • Fixed memory leak in Gd on very old versions of PHP #264
  • And more (view closed issues here

New in 2.6.0:

  • Introduced auto-limit option which replaces setting "quality" to "auto" #281
  • Added "sharp-yuv" option and made it default on. Its great, use it! Works in most converters (works in cwebp, vips, imagemagick, graphicsmagick, imagick and gmagick) #267, #280, #284
  • Bumped cwebp binaries to 1.2.0 #273
  • vips now supports "method" option and "preset" option.
  • graphicsmagick now supports "auto-filter" potion
  • vips, imagick, imagemagick, graphicsmagick and gmagick now supports "preset" option #275
  • cwebp now only validates hash of supplied precompiled binaries when necessary. This cuts down conversion time. #287
  • Added new option to cwebp for skipping precompiled binaries that are known not to work on current system. This will cut down on conversion time. #288
  • And more (view closed issues here)

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHP

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言