psliwa / image-optimizer

Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
MIT License
906 stars 141 forks source link

JPG image not compressing #68

Closed umairali closed 5 years ago

umairali commented 5 years ago

I am try to optimize the jpg image with below code but its not compressing. I tried with direct putty command with -m40 and its working but with this package i think its not taking -m40 in command.

$factory = new \ImageOptimizer\OptimizerFactory(array(
                                'ignore_errors' => false,
                                'jpegoptim_options' => array('-m40', '--strip-all', '--all-progressive')
                            ));
$optimizer = $factory->get();
$status = $optimizer->optimize($targetFile);

jpegoptim version jpegoptim v1.4.6 x86_64-redhat-linux-gnu

umairali commented 5 years ago

I found the issue. I installed jpegoptim and jpegtran both on server and in my custom options i was only sending -m40 for jpegoptim_options and the code is optimizing with jpegtran. now i add one more custom option jpegtran_options with -m40 and its working fine.

New Code

 $factory = new \ImageOptimizer\OptimizerFactory(array(
                                'ignore_errors' => false,
                                'jpegoptim_options' => array('-m40', '--strip-all', '--all-progressive'),
                                'jpegtran_options' => array('-m40', '-optimize', '-progressive'),
                            ));
$optimizer = $factory->get();
$status = $optimizer->optimize($targetFile);