![]() Let's take a look on how image-optimizer has been integrated in all of those. And lastly we have Browsershot, which can turn any webpage into an image. And we have laravel-medialibrary which can associate all kinds of files (including images) with Eloquent models. There also our image package which makes modifying images very easy. Our image-optimizer is not the first package we wrote the revolves around handling images. If you want to view an example implementation take a look at the existing optimizers that ship with the package. An optimizer is any class that implements the Spatie\ImageOptimizer\Optimizers\Optimizer interface. If you want to use another tool than the package supports out of the box, you can easily write your own optimizer. Here's an example where we only want optipng and jpegoptim to be used: use Spatie\ImageOptimizer\OptimizerChain use Spatie\ImageOptimizer\Optimizers\Jpegoptim use Spatie\ImageOptimizer\Optimizers\Pngquant $optimizerChain = ( new OptimizerChain ) -> addOptimizer ( new Jpegoptim ()) -> addOptimizer ( new Pngquant ()) If you want to customize the chain of optimizers you can do so by adding Optimizers manually to a OptimizerChain. -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 throug a second one: Optipng. We set no extra options, their defaults are used. The first one is Pngquant 2, a lossy PNG comprossor. 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 downloading using multiple passes of progressively higher details.-strip-all: this strips out all text information such as comments and EXIF data.JPGs will be made smaller by running them through JpegOptim. Like already mentioned, the package will automatically pick the right tool for the right image. The readme of the package includes instructions on how to install these on Ubuntu and MacOS. The package will use these optimizers if they are present on your system: The image at $pathToImage will be overwritten by an optimized version which should be smaller. use Spatie\ImageOptimizer\OptimizerChainFactory $optimizerChain = OptimizerChainFactory :: create () $optimizerChain -> optimize ($pathToImage) Optimizing an image is very easy using our package. It can find out which optimizers it should run, it can execute the binary and by default uses a set of optimizers with a sane configuration. Our package aims to do all of this out of the box. None of this is rocket science, but I bet that the vast majority of small to medium sites don't bother writing this code or researching these optimizations. ![]() You also have to decide which optimization parameters you're going to use for each tool. You must make sure that you pass the right kind of image to the right optimizer. What makes them a bit bothersome to use from PHP code is that you need to create a process to run them. ![]() These tools are free to use and can be easily installed on any system. In most cases these tools can make your images considerably smaller without you noticing, unless you have a trained eye for that. These tools, such as jpegtran, pngquant, and gifsicle, work more or less by applying a little bit of compression, removing metadata and reducing the number of colors. Now, to make images as small as they can be (without sacrificing a lot of detail) there are a lot of tools available. The less bytes the browser needs to download the faster the page will be. So to provide a fast page load it's best to make those images as small as they can be. In fact, in most cases images make up the bulk of the size of the entire page. On nearly every website we make, images are displayed. Here are a few images that were optimized by this package. In this blog post I'll tell you all about it.įirst, here's a quick example on how you can use it: use Spatie\ImageOptimizer\OptimizerChainFactory $optimizerChain = OptimizerChainFactory :: create () $optimizerChain -> optimize ($pathToImage) Our recently released image-optimizer package can shave off some kilobyes of PNGs, JPGs, SVGs and GIFs by running them through a chain of various image optimization tools. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |