[13.x] Fix incorrect image dimensions for HEIC - #61010
Merged
Merged
Conversation
zachiler
force-pushed
the
fix/image-heic-dimensions
branch
from
August 3, 2026 22:56
1b5ab5e to
08af07e
Compare
Image::dimensions(), width() and height() read the size with getimagesizefromstring(), which misreads HEIC: it returns false for large grid/tiled HEICs (so those methods throw) and reports the coded/padded frame size for smaller ones. For HEIC/HEIF, dimensions are now read from the driver, which decodes the image and reports its true display size, falling back to the native reader when the driver can't decode the image (e.g. the GD driver). Every other format is unchanged. Adds dimensions() to the Image\Driver contract and InterventionDriver, mirroring dominantColor(). Follow-up to laravel#60922. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
zachiler
force-pushed
the
fix/image-heic-dimensions
branch
from
August 4, 2026 19:50
08af07e to
8ae9200
Compare
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.
Image::dimensions(),width()andheight()read the size withgetimagesizefromstring(), which misreads HEIC — it either fails outright or reports the coded/padded frame size instead of the image's true display size:getimagesize(current)false→ throws* Large HEICs are stored as a grid of smaller tiles;
getimagesizecan't resolve the assembled size and returnsfalse(php-src #20863).So on an ordinary iPhone upload
->width()throws today, and on smaller HEICs it silently returns the wrong number. (The conversion pipeline is fine — it goes through the driver, notgetimagesize(); only the dimension inspectors are affected, which is what upload validation, aspect-ratio checks, and stored metadata rely on.)Fix
Follow-up to #60922, which added HEIC input/output support;
dimensions()was left reading viagetimagesizefromstring(). For HEIC/HEIF, dimensions are now read from the driver, which decodes the image and reports its true display size; every other format keeps its existing behaviour. HEIC requires the Imagick driver, so if the driver can't decode the image (e.g. GD) we fall back to the previousgetimagesize()path — the default GD driver is unaffected.Adds
dimensions(string $contents): arrayto theImage\Drivercontract andInterventionDriver, mirroringdominantColor()(#60932). Tests cover the driver routing, the GD fallback, and real-HEIC dimensions.