Skip to content

Fix VipsDriver autoRotate with sequential access - #328

Merged
freekmurze merged 2 commits into
spatie:mainfrom
thisispiers:patch-1
Jun 19, 2026
Merged

Fix VipsDriver autoRotate with sequential access#328
freekmurze merged 2 commits into
spatie:mainfrom
thisispiers:patch-1

Conversation

@thisispiers

Copy link
Copy Markdown
Contributor

According to libvips/libvips#4475 you can't rotate JPEGs with sequential access

thisispiers and others added 2 commits June 18, 2026 22:35
According to libvips/libvips#4475 you can't rotate JPEGs with sequential access
The autoRotate guard only copied the image into memory when the EXIF
orientation did NOT require a rotation, so the rotating orientations
(3, 5, 6, 7, 8) still hit "VipsJpeg: out of order read" when saving a
large sequential-access JPEG. Only copy into memory when a rotation
actually happens.

Add a test that loads a large oriented JPEG with the vips driver and
saves it. It fails with the old condition and passes with the fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@freekmurze

Copy link
Copy Markdown
Member

I pushed a couple of changes on top of this.

The condition was inverted: it copied the image into memory only when the orientation did not require a rotation (! in_array(..., [3, 5, 6, 7, 8])). But the orientations that actually rotate are exactly [3, 5, 6, 7, 8], so a large JPEG that needed rotating still hit VipsJpeg: out of order read on save. I flipped it to copy into memory only when a rotation happens.

I also added a regression test that builds a large (2000x1500) JPEG with a rotating EXIF orientation, loads it with the vips driver and saves it. The original testOrientation.jpg fixture is too small to exceed libvips' line cache, so the error only shows up on a larger image. The test fails with the old condition and passes with the fix.

@freekmurze
freekmurze merged commit 7ac0b9d into spatie:main Jun 19, 2026
5 checks passed
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