PHP code example of rosell-dk / webp-convert

1. Go to this page and download the library: Download rosell-dk/webp-convert library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rosell-dk / webp-convert example snippets


// Initialise your autoloader (this example is using Composer)
;
$destination = $source . '.webp';
$options = [];
WebPConvert::convert($source, $destination, $options);


use WebPConvert\WebPConvert;

$source = __DIR__ . '/logo.jpg';
$destination = $source . '.webp';

WebPConvert::serveConverted($source, $destination, [
    'fail' => 'original',     // If failure, serve the original image (source). Other options 
        ],
        'cache-control-header' => 'max-age=2',
    ],

    'convert' => [
        // all convert option can be entered here (ie "quality")
    ],
]);