spatie/image-optimizer
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
psr/log | 3.0.0 | 6.77 kB | MIT | prod | |
symfony/process | v7.0.7 | - | MIT | prod |
The Spatie Image Optimizer package offers an easy and efficient solution for optimizing images in PHP. It supports a variety of image formats such as PNGs, JPGs, WEBPs, AVIFs, SVGs, and GIFs. This tool functions by running images through a series of image optimization tools, resulting in reduced image size and improved loading times, all while maintaining the image quality.
Using the Spatie Image Optimizer is straightforward. Start by installing it via Composer with the command composer require spatie/image-optimizer
. Once installed, you can optimize an image file by executing a simple piece of code:
use Spatie\ImageOptimizer\OptimizerChainFactory;
$optimizerChain = OptimizerChainFactory::create();
$optimizerChain->optimize($pathToImage);
Where $pathToImage
is the path to your image.
Please keep in mind that the original image will be overwritten by its optimized version.
In case you want to keep the original image intact, you can use the optimize
method, providing a second argument as the place to write the optimized image:
$optimizerChain->optimize($pathToImage, $pathToOutput);
Where $pathToOutput
is the path to save the optimized image.
The documentation of Spatie Image Optimizer package can be read directly in the package's GitHub repository, here. The readme file contains step-by-step tutorials, code examples, details of functionalities, and contributing guidelines. It offers a comprehensive guide about how to use and customize the package according to your needs.