PHPackages                             rosell-dk/webp-on-demand - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. rosell-dk/webp-on-demand

ActiveLibrary[Image &amp; Media](/categories/media)

rosell-dk/webp-on-demand
========================

Serve autogenerated WebP images instead of jpeg/png to browsers that supports WebP

1.0.0(7y ago)76082[5 issues](https://github.com/rosell-dk/webp-on-demand/issues)MITPHPCI failing

Since Jul 8Pushed 7y ago1 watchersCompare

[ Source](https://github.com/rosell-dk/webp-on-demand)[ Packagist](https://packagist.org/packages/rosell-dk/webp-on-demand)[ RSS](/packages/rosell-dk-webp-on-demand/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (5)Versions (7)Used By (0)

WebP on demand
==============

[](#webp-on-demand)

This library is now part of [WebP Convert](https://github.com/rosell-dk/webp-convert/) and thus obsolete!
=========================================================================================================

[](#this-library-is-now-part-of-webp-convert-and-thus-obsolete)

This is a solution for automatically serving WebP images instead of jpeg/pngs for browsers that supports WebP (Google Chrome, that is).

Once set up, it will automatically convert images, no matter how they are referenced. It for example also works on images referenced in CSS. As the solution does not require any change in the HTML, it can easily be integrated into any website / framework (A Wordpress adaptation was recently published on [wordpress.org](https://wordpress.org/plugins/webp-express/) - its also on [github](https://github.com/rosell-dk/webp-express))

***NOTE: This library will be part of WebP Convert soon (depreciated, that is)***

Overview
--------

[](#overview)

A setup consists of these parts:

- *Redirect rules* that redirects JPG/PNG images to a PHP script.
- *A PHP script* that serves a converted image - by calling *WebPOnDemand::convert()* method of this library.
- *WebPOnDemand::convert()*. Detects if an existing converted image can be served. If yes, serves it (unless the original has been modified). Otherwise it converts the image using the [webp-convert-and-serve](https://github.com/rosell-dk/webp-convert-and-serve) library.

Requirements
------------

[](#requirements)

- *Apache* or *LiteSpeed* web server. Can be made to work with *NGINX* as well. Documentation is on the roadmap.
- PHP &gt;= 5.6 (we are only testing down to 5.6. It should however work in 5.5 as well)
- That one of the *webp-convert* converters are working (these have different requirements)

Installation
------------

[](#installation)

The first two steps are whether you are going to use composer or not. [Not using composer? - Follow me!](https://github.com/rosell-dk/webp-on-demand/blob/master/docs/install-without-composer.md)

### 1. Require this library with composer

[](#1-require-this-library-with-composer)

`composer require rosell-dk/webp-on-demand`

### 2. Create the script

[](#2-create-the-script)

Create a file *webp-on-demand.php*, and place it in webroot, or where-ever you like in you web-application.

Here is a minimal example to get started with:

```
