Skip to content

fix: apply EXIF rotation in crop pipeline and add regression tests#16350

Open
robinvangestel21 wants to merge 1 commit intopayloadcms:mainfrom
robinvangestel21:fix/exif-crop-rotation
Open

fix: apply EXIF rotation in crop pipeline and add regression tests#16350
robinvangestel21 wants to merge 1 commit intopayloadcms:mainfrom
robinvangestel21:fix/exif-crop-rotation

Conversation

@robinvangestel21
Copy link
Copy Markdown

What?

This PR fixes EXIF-orientation handling in the upload crop pipeline.
Specifically:

  • apply sharp().rotate() before .extract(...) in cropImage so crop coordinates are applied in the same oriented coordinate space as other upload transforms
  • apply .rotate() in the animated metadata read path used by the no-op crop branch to keep dimension handling consistent
  • add regression tests in cropImage.spec.ts for:
    • EXIF-oriented crop behavior

Why?

Cropping images with EXIF orientation > 1 could behave incorrectly because crop extraction was not using the same EXIF-normalized orientation path as the rest of upload processing.
This could lead to:

  • wrong crop orientation / flipped output
  • in some cases, crop failures (e.g. bad extract area) due to coordinate mismatch
    Related issue: #16347

How?

  • Updated packages/payload/src/uploads/cropImage.ts:
    • added .rotate() before metadata read in the animated branch
    • added .rotate() before crop .extract(...)
  • Added packages/payload/src/uploads/cropImage.spec.ts with targeted regression coverage
  • Verified test run:

@robinvangestel21 robinvangestel21 changed the title fix(payload): apply EXIF rotation in crop pipeline and add regression tests fix: apply EXIF rotation in crop pipeline and add regression tests Apr 22, 2026
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.

Cropping image with EXIF orientation > 1 fails

1 participant