PHP code example of bensquire / php-image-optim

1. Go to this page and download the library: Download bensquire/php-image-optim 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/ */

    

bensquire / php-image-optim example snippets


$tool = new \PHPImageOptim\Tools\Jpeg\MozJpeg();
$tool->setBinaryPath('/usr/local/opt/mozjpeg/bin/jpegtran');


    PHPImageOptim\Tools\Png\AdvPng;
    use PHPImageOptim\Tools\Png\OptiPng;
    use PHPImageOptim\Tools\Png\PngCrush;
    use PHPImageOptim\Tools\Png\PngOut;
    use PHPImageOptim\Tools\Png\PngQuant;

    $advPng = new AdvPng();
    $advPng->setBinaryPath('/usr/local/bin/advpng');

    $optiPng = new OptiPng();
    $optiPng->setBinaryPath('/usr/local/bin/optipng');

    $pngOut = new PngOut();
    $pngOut->setBinaryPath('/usr/bin/pngout');

    $pngCrush = new PngCrush();
    $pngCrush->setBinaryPath('/usr/local/bin/pngcrush');

    $pngQuant = new PngQuant();
    $pngQuant->setBinaryPath('/usr/local/bin/pngquant');

    $optim = new PHPImageOptim();
    $optim->setImage('./tests/image/lenna.png');
    $optim->chainCommand($pngQuant)
        ->chainCommand($advPng)
        ->chainCommand($optiPng)
        ->chainCommand($pngCrush)
        ->chainCommand($pngOut);
    $optim->optimise();

composer 
console
    composer php-stan