##Requirements
Optimization of images is done by the underlying spatie/image-optimizer package. It assumes that there are a few optimization tools, such as JpegOptim an Pngquant present on your system. For more info, check out the relevant docs.
##How to use
To shave off some kilobytes of the images the package can optimize images by calling the optimize
method.
Here's the original image of New York used in all examples has a size of 622 Kb. Let's optimize it.
Image::load('example.jpg')
->optimize()
->save('example-optimized.jpg');
.
The size of the optimized image is 573 Kb.
No matter where or how many times you call optimize
in you chain, it will always be performed as the last operation once.
##Customizing the optimization
You can customize the optimization by passing an OptimizerChain
instance to the optimize
method.
For the OptimizerChain
instance you can also set the maximum of time in seconds that each individual optimizer in a chain can use by calling setTimeout
. The default value is 60 seconds. Adjusting this setting may be inevitable while working with large images (see e.g. #187).
$optimizerChain = (new OptimizerChain)
->addOptimizer(new Jpegoptim([
'--strip-all',
'--all-progressive',
'-m85'
]))
->setTimeout(90);
Image::load('example.jpg')
->optimize($optimizerChain)
->save();