PicoWebP adds WebP conversion to PHP applications when the server’s image tools are unavailable or outside your control. Install it through Composer and convert images inside your application, without adding an image extension, running a command-line encoder or sending files to a conversion service.
Where PicoWebP fits
- Shared and restricted hosting. Your application needs WebP output, but you cannot enable GD or Imagick, install cwebp, or run shell commands.
- Existing PHP applications and APIs. Add image conversion to an established service without introducing native image-processing software into its deployment.
- PHP plugins and distributed software. Provide a conversion fallback when customers’ hosting environments have different image capabilities. Your application can use native tools where available and PicoWebP where they are missing.
PHP on AWS Lambda and Bref
PicoWebP is also an option to consider when packaging image-processing dependencies makes a serverless deployment more complicated.
Bref supports GD and Imagick through additional Lambda layers and Docker images. PicoWebP provides another approach: keep WebP encoding in the PHP application itself. Whether that is a useful trade-off depends on your image sizes, conversion volume and execution limits.
Supported images
The bundled readers handle PNG, BMP and baseline JPEG files without GD. You can also pass raw RGB pixels directly to the encoder.
PicoWebP preserves transparency and embedded ICC colour profiles. Colour compression is lossy; transparency is compressed losslessly. Existing WebP files are recognised from their contents and skipped by default, even when the filename has the wrong extension.
Progressive JPEG input and re-encoding an existing WebP require GD.
Performance and background processing
Pure-PHP encoding takes substantially more CPU time than native tools. In the recorded benchmark, encoding a roughly one-megapixel image took about 25 seconds with the default settings. Larger images can take minutes.
Use PicoWebP for background conversion with sensible image-size limits. Where a native encoder is available, it is generally the better choice for processing large volumes of images.
For longer jobs, resumable encoding lets your application save progress and continue in another invocation. Your application supplies the scheduling and state storage; splitting the work does not make the conversion faster.
Installation and requirements
Install the package with composer require nikocodes/picowebp.
PicoWebP requires PHP 8.1 or newer and zlib. It includes a PHP API and a command-line interface.
See the installation instructions, examples and benchmarks.
For Node.js and browser applications, see PicoWebPJS.