"Explore the new first-party image processing features introduced in Laravel 13.20. This tutorial covers installation, image resizing, cropping, format conversion, optimization, and practical examples to help you process images efficiently using Laravel's built-in image manipulation tools."
Laravel 13.20 First-Party Image Processing: Features, Usage & Examples
Laravel 13.20.0 introduces built-in first-party image processing, featuring an immutable, driver-based API that makes it easy to manipulate images from uploads, storage, URLs, or raw binary data.
-
Built-in first-party image processing powered by the new
Imagefacade.
What's New
First-Party Image Processing
Laravel 13.20 introduces an component that handles resizing, cropping, format conversion, and storage without reaching for a third-party wrapper.
Illuminate\Image
Images are immutable: every transformation returns a new instance, and the queued transformations are applied when you ask for the result.
The most common path starts with an upload. returns an Request::image() instance for a given file key, or Image if the key does not hold an uploaded file:
null
$request->image('avatar')
->cover(200, 200)
->toWebp()
->store('avatars');
You can also create an image instance from a local file path, a remote URL, raw binary data, a Base64-encoded string, or a file stored on any configured storage disk.
Image::fromPath('/path/to/photo.jpg');
Image::fromUrl('https://example.com/photo.jpg');
Image::fromBytes($bytes);
Image::fromStorage('photos/avatar.jpg', 's3');
Storage::disk('s3')->image('photos/avatar.jpg');
Transformations, output options, and inspection methods are all available on the instance:
// Transformations...
$image->cover(200, 200);
$image->contain(800, 600);
$image->crop(200, 200);
$image->resize(1024, 768);
$image->scale(1200, 800);
$image->rotate(90);
$image->blur(10);
$image->sharpen(10);
$image->grayscale();
$image->flip();
$image->flop();
$image->orient(); // Applies EXIF rotation...
// Output format and quality...
$image->toWebp();
$image->toJpg()->quality(80);
$image->optimize(); // WebP at quality 70...
$image->optimize('jpg', 85);
// Reading and inspecting...
$image->toBytes();
$image->toBase64();
$image->toDataUri();
$image->width();
$image->height();
$image->dimensions();
$image->mimeType();
$image->extension();
Since image instances are immutable, you can create multiple image variations from a single source without modifying the original image.
$image = $request->image('photo');
$image->cover(200, 200)->toWebp()->store('thumbnails');
$image->grayscale()->toWebp()->store('grayscale');
The image processing component includes two built-in drivers—GD and Imagick—both powered by Intervention Image v4. You can choose the appropriate driver for each image, while the facade also allows you to customize how individual image transformations are handled by each driver.
Image
use Illuminate\Image\Transformations\Sharpen;
// Pick a driver per image...
$image->using('imagick');
$image->usingGd();
$image->usingImagick();
// Override how a driver handles a transformation...
Image::transformUsing('gd', Sharpen::class, function ($image, Sharpen $sharpen) {
// Custom sharpen handling for the GD driver...
return $image;
});
Intervention Image is a suggested dependency rather than a required one, so you install it yourself:
composer require intervention/image