Skip to content

Fixed unhandled, or broken, EXIF orientations in GD Driver.#322

Merged
freekmurze merged 4 commits intospatie:mainfrom
GarethSomers:gd-orientations
Mar 13, 2026
Merged

Fixed unhandled, or broken, EXIF orientations in GD Driver.#322
freekmurze merged 4 commits intospatie:mainfrom
GarethSomers:gd-orientations

Conversation

@GarethSomers
Copy link
Contributor

@GarethSomers GarethSomers commented Mar 13, 2026

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

image

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:
Screenshot 2026-03-13 at 4 14 36 pm

And after:

Screenshot 2026-03-13 at 4 25 45 pm

@GarethSomers GarethSomers changed the title Addressing unhandled, and correcting, exif orientations in GD Driver. Fixed unhandled, or broken, EXIF orientations in GD Driver. Mar 13, 2026
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.
@freekmurze freekmurze merged commit 6a322b5 into spatie:main Mar 13, 2026
5 checks passed
@freekmurze
Copy link
Member

Thanks for the contribution, @GarethSomers! Great catch on the missing GD orientations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants