lciolecki/php-image-optimizer

PHP image file optimizer (uses https://github.com/bensquire/php-image-optim)

v0.0.1 2014-12-16 08:24 UTC

This package is not auto-updated.

Last update: 2024-11-20 14:02:47 UTC


README

This is a simple PHP class for optimize image file uses https://github.com/bensquire/php-image-optim (png, jpeg, gif). Requires: optipng, jpegoptim, gifsicle

##Installation using Composer

{
    "minimum-stability": "dev",
    "require": {
        "lciolecki/php-image-optimizer": "dev-master"
    }
}

Sample use

$optimizer = new \Extlib\ImageOptimizer(array(
    \Extlib\ImageOptimizer::OPTIMIZER_OPTIPNG => '/usr/bin/optipng',  //your_path
    \Extlib\ImageOptimizer::OPTIMIZER_JPEGOPTIM => '/usr/bin/jpegoptim', //your_path
    \Extlib\ImageOptimizer::OPTIMIZER_GIFSICLE => '/usr/bin/gifsicle' //your_path
));

$optimizer->optimize("image.png"); //return true
$optimizer->optimize("image.jpg"); //return true
$optimizer->optimize("image.gif"); //return true
$optimizer->optimize("file.txt"); //return false

If you don't have some one of packages: optipng, jpegoptim, gifsicle optimizer throws Exception. For save uses take all code in try/catch block.