Fixed unhandled, or broken, EXIF orientations in GD Driver.#322
Merged
freekmurze merged 4 commits intospatie:mainfrom Mar 13, 2026
Merged
Fixed unhandled, or broken, EXIF orientations in GD Driver.#322freekmurze merged 4 commits intospatie:mainfrom
freekmurze merged 4 commits intospatie:mainfrom
Conversation
Adds test fixture images for each EXIF orientation (1-8) and a test that verifies both GD and Imagick drivers produce the correct dimensions after auto-rotation.
Generates test images on-the-fly from the existing testOrientation.jpg instead of maintaining separate fixture files for each orientation.
Instead of 16 identical snapshot files, generate test images on-the-fly and use pixelmatch to verify all orientations produce the same result as orientation 1 after auto-rotation.
Member
|
Thanks for the contribution, @GarethSomers! Great catch on the missing GD orientations. |
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.
Problem
GD Driver does not handle all EXIF Orientation(s) when auto-rotating. Sometimes the images can be rotated, and flipped. Each orientation is identified by a number, which is visualised below.
Interestingly the Imagick driver already handles each scenario: https://github.com/spatie/image/blob/main/src/Drivers/Imagick/ImagickDriver.php#L662
Solution
Expand upon the handled orientations to take into account each, and additionally flip when required.
Each has been tested against these images: https://github.com/recurser/exif-orientation-examples
Here is a gallery before the update:

And after: