I built PicoWebP for an annoying hosting problem: PHP is available, but the image tools needed to produce WebP aren’t. “Just install GD” is reasonable advice when you control the server. Less useful when you don’t.
PicoWebP includes its own PNG and baseline JPEG readers, and the encoder writes the VP8 bitstream in PHP. It can take an image all the way to a WebP file without GD, Imagick, libwebp, a command-line converter or an external service.
That turned into quite a bit more than changing a file extension. Transparent PNGs need their alpha preserved. Embedded colour profiles need to survive the conversion. Existing WebP files should be recognised and skipped, even when somebody has given them the wrong extension.
There is a fairly obvious price for doing this in PHP: time. With the default settings, encoding a roughly one-megapixel image took about 25 seconds on the benchmark machine. Large photos take minutes. If a native encoder is available, use it.
For longer jobs, there is a resumable encoding path so an application can save its progress and continue in another invocation. It still does the same expensive work, but that work can be scheduled in smaller pieces.
PicoWebP is available as a Composer package with a PHP API and a CLI. It requires PHP 8.1 or newer and zlib. Progressive JPEG input still needs GD; PNGs and baseline JPEGs work with the bundled readers.