Skip to content

Allow rotation transformation without angle argument #590

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

markatom
Copy link

Issue #, if available:

Related: github.com//issues/495

Description of changes:

This change enables the rotate filter to be used without an angle argument (e.g., filters:rotate()). The previous implementation would parse this as 0 and pass it to sharp.rotate().

The new implementation takes advantage of Sharp's behavior when rotate() is called without arguments:

  1. It automatically determines the rotation angle from the EXIF data
  2. It supports mirroring operations when needed
  3. It removes the EXIF Orientation tag after applying the rotation

This change helps fix issues with images that contain EXIF orientation metadata but are displayed incorrectly in clients (e.g., browsers) that don't support EXIF orientation.

Reference: Sharp Documentation - rotate

Note: I have verified that the change works as expected, but additional unit tests may be needed to ensure proper coverage.

Checklist

  • 👋 I have added unit tests for all code changes.
  • 👋 I have run the unit tests, and all unit tests have passed.
  • ⚠️ This pull request might incur a breaking change.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@markatom
Copy link
Author

Related
#537
#540

@gsingh04
Copy link
Member

Thanks @markatom for the PR and apologies for the delay here.

It does seem confusing to deviate from the sharp default behavior. One thing I noticed after applying your changes, we still need to update here as well.

? sharp(originalImage, options).withMetadata({ orientation: metadata.orientation })

For me this seemed to interfere with the default behavior, probably because we overwrite the orientation metadata. After fixing this I was able to get following results

url - https://myDomain/filters:rotate()/myImage.jpeg
original image - Orientation: 6 (Rotated 90° CCW)
changed image -
Screenshot 2025-04-17 at 4 46 29 PM

@gsingh04
Copy link
Member

We have added this to our backlog and will fix the behavior in upcoming releases.

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