Skip to content

lciolecki/php-image-optimizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Image optimizer

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.