[13.x] Adds first-party support for image processing#59276
Draft
nunomaduro wants to merge 10 commits into13.xfrom
Draft
[13.x] Adds first-party support for image processing#59276nunomaduro wants to merge 10 commits into13.xfrom
image processing#59276nunomaduro wants to merge 10 commits into13.xfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hey! This one's still cooking — not ready for review yet, just sharing progress. 🚧
This PR adds first-party support for image processing in Laravel via a driver-based API that allows developers to manipulate uploaded images fluently from requests.
Getting Started
Process an uploaded image in a single, fluent chain:
The
image()method on the request returns aPendingImageinstance that wraps the uploaded file. Operations (like optimize or cover) are accumulated and applied when a terminal method likestore()is called — or explicitly viaprocess().Available Operations
optimize(string $format = 'webp', int $quality = 80)
Convert to a given format and quality level:
cover(int $width, int $height)Resize and crop the image to exactly fit the given dimensions, maintaining aspect ratio:
scale(int $width, int $height)Resize the image proportionally. If only width is given, the height is calculated automatically:
orient()Auto-orient the image based on EXIF data — fixes photos taken on phones that appear rotated:
blur(int $amount = 5)Apply a blur effect. Useful for generating placeholder images for lazy loading:
greyscale()Convert the image to greyscale:
Real-World Pipelines
Drivers
The image processing is driver-based. Three drivers are included:
gd,imagick, andcloudflare.The default driver is configured in config/image.php:
'default' => env('IMAGE_DRIVER', 'gd'),
GD and Imagick use Intervention Image v3 under the hood. You can override the driver per-image:
The Cloudflare driver uses the Cloudflare Images API — uploading the image, applying transformations via URL parameters, and downloading the result:
Custom drivers can be registered via extend():