Notice that you can pass the options an Optimizer should use to its constructor. Use Spatie\ ImageOptimizer\ Optimizers\ Pngquant Use Spatie\ ImageOptimizer\ Optimizers\ Jpegoptim Here's an example where we only want optipng and jpegoptim to be used: use Spatie\ ImageOptimizer\ OptimizerChain If you want to customize the chain of optimizers you can do so by adding Optimizers manually to an OptimizerChain. In this example each optimizer in the chain will get a maximum 10 seconds to do it's job. You can set the maximum of time in seconds that each individual optimizer in a chain can use by calling setTimeout: $optimizerChain In that example the package won't touch $pathToImage and write an optimized version to $pathToOutput. ![]() $optimizerChain-> optimize( $pathToImage, $pathToOutput) To keep the original image, you can pass through a second argument optimize: use Spatie\ ImageOptimizer\ OptimizerChainFactory The package will automatically detect which optimization binaries are installed on your system and use them. The image at $pathToImage will be overwritten by an optimized version which should be smaller. This is the default way to use the package: use Spatie\ ImageOptimizer\ OptimizerChainFactory (Settings are original taken from here) Usage -q 90 Quality factor that brings the least noticeable changes.-mt multithreading for some speed improvements.-pass 10 for maximizing the amount of analysis pass.-m 6 for the slowest compression method in order to get the best compression.-O3: this sets the optimization level to Gifsicle's maximum, which produces the slowest but best results.You'll find more info on that in this excellent blogpost by Sara Soueidan. Please be aware that SVGO can break your svg. SVGO's default configuration will be used, with the omission of the cleanupIDs and removeViewBox plugins because these are known to cause troubles when displaying multiple optimized SVGs on one page. -o2: this set the optimization level to two (multiple IDAT compression trials).-i0: this will result in a non-interlaced, progressive scanned image.After that we run the image through a second one: Optipng. We set no extra options, their defaults are used. The first one is Pngquant 2, a lossy PNG compressor. PNGs will be made smaller by running them through two tools. -all-progressive: this will make sure the resulting image is a progressive one, meaning it can be downloaded using multiple passes of progressively higher details.-strip-all: this strips out all text information such as comments and EXIF data.This setting seems to satisfy Google's Pagespeed compression rules -m85: this will store the image with 85% quality.JPGs will be made smaller by running them through JpegOptim. The package will automatically decide which tools to use on a particular image. Sudo dnf install libwebp-tools Which tools will do what? Here's how to install all the optimizers on Ubuntu: sudo apt-get install jpegoptimĪnd here's how to install the binaries on MacOS (using Homebrew): brew install jpegoptimĪnd here's how to install the binaries on Fedora/RHEL/CentOS: sudo dnf install epel-release The package will use these optimizers if they are present on your system: You can install the package via composer: composer require spatie/image-optimizer Optimization tools We publish all received postcards on our virtual postcard wall. You'll find our address on our contact page. We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You can support us by buying one of our paid products. We invest a lot of resources into creating best in class open source packages. SilverStripe enthusiast? Don't waste time, go to the SilverStripe module. Using WordPress? Then try out the WP CLI command. Loving Laravel? Then head over to the Laravel specific integration. Here are some example conversions that have been done by this package. ![]() $optimizerChain-> optimize( $pathToImage) $optimizerChain = OptimizerChainFactory:: create() Here's how you can use it: use Spatie\ ImageOptimizer\ OptimizerChainFactory This package can optimize PNGs, JPGs, SVGs and GIFs by running them through a chain of various image optimization tools.
0 Comments
Leave a Reply. |