New Major Versions of Spatie Image and Laravel Media Library Released
Last updated on by Paul Redmond
Spatie released the next major version (v3) of their popular spatie/image package, which also powers their laravel-medialibrary package. If you're looking for an image maniuplation library without any dependencies, you should check out this version.
The latest version of the image package is a major overhaul of the internals of the library, yet the public API hasn't changed much. This version doesn't depend on the PHP intervention package; the only dependencies are the Imagick or GD extensions.
Here's an example of the fluent API you can use to manipulate and image and save an updated version:
Image::load('example.jpg') ->sepia() ->blur(50) ->save();
If you're not familiar with Spatie's Image package, it provides a fluent API for the following image manipulations:
- Resizing images
- Image optimization
- Image adjustments
- Image canvas manipulation
- Image effects (blur, grayscale, pixelate, etc.)
- Image watermarks
- And more...
Take a look at this example of how you can easily optimize an image with this package:
Image::load('example.jpg') ->optimize() ->save('example-optimized.jpg');
That's a simple example, but you can customize the optimization process with more advanced options:
Image::load('example.jpg') ->optimize([Jpegoptim::class => [ '--all-progressive', ]]) ->save();
The easiest way to get started with this package is to read the documentation. You can also use this package in your Laravel applications via the popular laravel-medialibrary.
If you'd like to get more of a behind-the-scenes look at the Spatie Image package update, read Freek Van der Herten's detailed writeup: New major versions for spatie/image and Laravel Media Library have been released.