Optimization of images is done by the underlying spatie/image-optimizer. 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
Here's the original image of New York used in all examples has a size of 622 Kb. Let's optimize it.
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
To optimization of images is done by the underlying spatie/image-optimizer package. You can pass your own customized chains as array. The keys should be fully qualified class names of optimizers and the values the options that they should get. Here's an example
->optimize([Jpegoptim::class => [
If you need more control over the optimizer chain, you can still pass your own instance of
OptimizerChain. It can be especially useful if you need to set a custom timeout or a custom binary path. You may not have enough privileges to install the necessary binaries on your server but you can still upload some precompiled binaries.
$optimizer = new OptimizerChain();