# The webp converters ## The converters at a glance When it comes to webp conversion, there is actually only one library in town: *libwebp* from Google. All conversion methods below ultimately uses that very same library for conversion. This means that it does not matter much, which conversion method you use. Whatever works. There is however one thing to take note of, if you set *quality* to *auto*, and your system cannot determine the quality of the source (this requires imagick or gmagick), and you do not have access to install those, then the only way to get quality-detection is to connect to a *wpc* cloud converter. However, with *cwebp*, you can specify the desired reduction (the *size-in-percentage* option) - at the cost of doubling the conversion time. Read more about those considerations in the API. Speed-wise, there is too little difference for it to matter, considering that images usually needs to be converted just once. Anyway, here are the results: *cweb* is the fastest (with method=3). *gd* is right behind, merely 3% slower than *cwebp*. *gmagick* are third place, ~8% slower than *cwebp*. *imagick* comes in ~22% slower than *cwebp*. *ewww* depends on connection speed. On my *digital ocean* account, it takes ~2 seconds to upload, convert, and download a tiny image (10 times longer than the local *cwebp*). A 1MB image however only takes ~4.5 seconds to upload, convert and download (1.5 seconds longer). A 2 MB image takes ~5 seconds to convert (only 16% longer than my *cwebp*). The *ewww* thus converts at a very decent speeds. Probably faster than your average shared host. If multiple big images needs to be converted at the same time, *ewww* will probably perform much better than the local converters. [`cwebp`](#cwebp) works by executing the *cwebp* binary from Google, which is build upon the *libwebp* (also from Google). That library is actually the only library in town for generating webp images, which means that the other conversion methods ultimately uses that very same library. Which again means that the results using the different methods are very similar. However, with *cwebp*, we have more parameters to tweak than with the rest. We for example have the *method* option, which controls the trade off between encoding speed and the compressed file size and quality. Setting this to max, we can squeeze the images a few percent extra - without loosing quality (the converter is still pretty fast, so in most cases it is probably worth it). Of course, as we here have to call a binary directly, *cwebp* requires the *exec* function to be enabled, and that the webserver user is allowed to execute the `cwebp` binary (either at known system locations, or one of the precompiled binaries, that comes with this library). [`vips`](#vips) (**new in 2.0**) works by using the vips extension, if available. Vips is great! It offers many webp options, it is fast and installation is easier than imagick and gd, as it does not need to be configured for webp support. [`imagick`](#imagick) does not support any special webp options, but is at least able to strip all metadata, if metadata is set to none. Imagick has a very nice feature - that it is able to detect the quality of a jpeg file. This enables it to automatically use same quality for destination as for source, which eliminates the risk of setting quality higher for the destination than for source (the result of that is that the file size gets higher, but the quality remains the same). As the other converters lends this capability from Imagick, this is however no reason for using Imagick rather than the other converters. Requirements: Imagick PHP extension compiled with WebP support [`gmagick`](#gmagick) uses the *gmagick* extension. It is very similar to *imagick*. Requirements: Gmagick PHP extension compiled with WebP support. [`gd`](#gd) uses the *Gd* extension to do the conversion. The *Gd* extension is pretty common, so the main feature of this converter is that it may work out of the box. It does not support any webp options, and does not support stripping metadata. Requirements: GD PHP extension compiled with WebP support. [`wpc`](#wpc) is an open source cloud service for converting images to webp. To use it, you must either install [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service) directly on a remote server, or install the Wordpress plugin, [WebP Express](https://github.com/rosell-dk/webp-express) in Wordpress. Btw: Beware that upload limits will prevent conversion of big images. The converter checks your *php.ini* settings and abandons upload right away, if an image is larger than your *upload_max_filesize* or your *post_max_size* setting. Requirements: Access to a running service. The service can be installed [directly](https://github.com/rosell-dk/webp-convert-cloud-service) or by using [this Wordpress plugin](https://wordpress.org/plugins/webp-express/) [`ewww`](#ewww) is also a cloud service. Not free, but cheap enough to be considered *practically* free. It supports lossless encoding, but this cannot be controlled. *Ewww* always uses lossy encoding for jpeg and lossless for png. For jpegs this is usually a good choice, however, many pngs are compressed better using lossy encoding. As lossless cannot be controlled, the "lossless:auto" option cannot be used for automatically trying both lossy and lossless and picking the smallest file. Also, unfortunately, *ewww* does not support quality=auto, like *wpc*, and it does not support *size-in-percentage* like *cwebp*, either. I have requested such features, and he is considering... As with *wpc*, beware of upload limits. Requirements: A key to the *EWWW Image Optimizer* cloud service. Can be purchaced [here](https://ewww.io/plans/) [`stack`](#stack) takes a stack of converters and tries it from the top, until success. The main convert method actually calls this converter. Stacks within stacks are supported (not really needed, though). **Summary:** | | cwebp | vips | imagickbinary | imagick / gmagick | gd | ewww | | ------------------------------------------ | --------- | ------ | -------------- | ----------------- | --------- | ------ | | supports lossless encoding ? | yes | yes | yes | no | no | yes | | supports lossless auto ? | yes | yes | yes | no | no | no | | supports near-lossless ? | yes | yes | no | no | no | ? | | supports metadata stripping / preserving | yes | yes | yes | yes | no | ? | | supports setting alpha quality | yes | yes | yes | no | no | no | | supports fixed quality (for lossy) | yes | yes | yes | yes | yes | yes | | supports auto quality without help | no | no | yes | yes | no | no | *WebPConvert* currently supports the following converters: | Converter | Method | Requirements | | ------------------------------------ | ------------------------------------------------ | -------------------------------------------------- | | [`cwebp`](#cwebp) | Calls `cwebp` binary directly | `exec()` function *and* that the webserver user has permission to run `cwebp` binary | | [`vips`](#vips) (new in 2.0) | Vips extension | Vips extension | | [`imagick`](#imagick) | Imagick extension (`ImageMagick` wrapper) | Imagick PHP extension compiled with WebP support | | [`gmagick`](#gmagick) | Gmagick extension (`ImageMagick` wrapper) | Gmagick PHP extension compiled with WebP support | | [`gd`](#gd) | GD Graphics (Draw) extension (`LibGD` wrapper) | GD PHP extension compiled with WebP support | | [`imagickbinary`](#imagickbinary) | Calls imagick binary directly | exec() and imagick installed and compiled with WebP support | | [`wpc`](#wpc) | Connects to an open source cloud service | Access to a running service. The service can be installed [directly](https://github.com/rosell-dk/webp-convert-cloud-service) or by using [this Wordpress plugin](https://wordpress.org/plugins/webp-express/). | [`ewww`](#ewww) | Connects to *EWWW Image Optimizer* cloud service | Purchasing a key | ## Installation Instructions regarding getting the individual converters to work are [on the wiki](https://github.com/rosell-dk/webp-convert/wiki) ## cwebp
Requirements | exec() function and that the webserver has permission to run `cwebp` binary (either found in system path, or a precompiled version supplied with this library) |
---|---|
Performance | ~40-120ms to convert a 40kb image (depending on *method* option) |
Reliability | No problems detected so far! |
Availability | According to ewww docs, requirements are met on surprisingly many webhosts. Look here for a list |
General options supported | All (`quality`, `metadata`, `lossless`) |
Extra options | `method` (0-6) `use-nice` (boolean) `try-common-system-paths` (boolean) `try-supplied-binary-for-os` (boolean) `autofilter` (boolean) `size-in-percentage` (number / null) `command-line-options` (string) `low-memory` (boolean) |
Requirements | Vips extension |
---|---|
Performance | Great |
Reliability | No problems detected so far! |
Availability | Not that widespread yet, but gaining popularity |
General options supported | All (`quality`, `metadata`, `lossless`) |
Extra options | `smart-subsample`(boolean) `alpha-quality`(0-100) `near-lossless` (0-100) `preset` (0-6) |
Requirements | Access to a server with [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service) installed, cURL and PHP >= 5.5.0 |
---|---|
Performance | Depends on the server where [webp-convert-cloud-service](https://github.com/rosell-dk/webp-convert-cloud-service) is set up, and the speed of internet connections. But perhaps ~1000ms to convert a 40kb image |
Reliability | Great (depends on the reliability on the server where it is set up) |
Availability | Should work on almost any webhost |
General options supported | All (`quality`, `metadata`, `lossless`) |
Extra options (old api) | `url`, `secret` |
Extra options (new api) | `url`, `api-version`, `api-key`, `crypt-api-key-in-transfer` |
Requirements | Valid EWWW Image Optimizer API key, cURL and PHP >= 5.5.0 |
---|---|
Performance | ~1300ms to convert a 40kb image |
Reliability | Great (but, as with any cloud service, there is a risk of downtime) |
Availability | Should work on almost any webhost |
General options supported | `quality`, `metadata` (partly) |
Extra options | `key` |
Requirements | GD PHP extension and PHP >= 5.5.0 (compiled with WebP support) |
---|---|
Performance | ~30ms to convert a 40kb image |
Reliability | Not sure - I have experienced corrupted images, but cannot reproduce |
Availability | Unfortunately, according to this link, WebP support on shared hosts is rare. |
General options supported | `quality` |
Extra options | `skip-pngs` |
Requirements | Imagick PHP extension (compiled with WebP support) |
---|---|
Quality | Poor. [See this issue]( https://github.com/rosell-dk/webp-convert/issues/43) |
General options supported | `quality` |
Extra options | None |
Performance | ~20-320ms to convert a 40kb image |
Reliability | No problems detected so far |
Availability | Probably only available on few shared hosts (if any) |
Requirements | exec() function and that imagick is installed on webserver, compiled with webp support |
---|---|
Performance | just fine |
Reliability | No problems detected so far! |
Availability | Not sure |
General options supported | `quality` |
Extra options | `use-nice` (boolean) |
General options supported | all (passed to the converters in the stack ) |
---|---|
Extra options | `converters` (array) and `converter-options` (array) |