Skip to content

Keep rotated crop area inside the image - #442

Merged
mosch merged 3 commits into
mainfrom
fix/rotation-crop-boundary
Sep 30, 2026
Merged

mosch merged 3 commits into
mainfrom
fix/rotation-crop-boundary

Conversation

@mosch

@mosch mosch commented Sep 30, 2026

Copy link
Copy Markdown
Owner

Fixes #377

When the image was rotated, the drag boundary still assumed an unrotated crop. You could drag it until empty corners showed, and the exported image had them too. With the default disableCanvasRotation, what you see is the crop rect turned around its center. getCroppingRect now keeps that turned rect's bounding box inside the image, which is exact because the image is axis-aligned in its own coordinates. If the turned rect can't fit at the current zoom, the crop is centered on that axis.

  • No change at 0°/180°, with disableBoundaryChecks, or when the crop is larger than the image.
  • With disableCanvasRotation={false}, the canvas turns along with the image, so the extra 90° is subtracted. Clamping at 90°/270° behaves as before.
  • Drag and keyboard both go through getCroppingRect, so both are covered.

Tests: 8 new core tests. They check that the rotated crop's corners stay inside the image across angles (15, 45, -30, 90, 100, 200°) and drag positions, and cover the "can't fit → center" case and the canvas-rotation mode. 7 of them fail without the fix. The Playwright visual tests (rotation 90/120/180) pass unchanged.

The boundary clamp ignored rotation, so with a rotated image the crop
could show empty corners. Clamp the bounding box of the rotated crop
rect instead, and center it when it cannot fit.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
react-avatar-editor 4e2dbfe Commit Preview URL

Branch Preview URL
Sep 30 2026, 05:06 PM

@mosch

mosch commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

@copilot resolve the merge conflicts in this pull request

…ndary

# Conflicts:
#	CHANGELOG.md

Co-authored-by: mosch <224866+mosch@users.noreply.github.com>

Copilot AI commented Sep 30, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts in this pull request

Resolved the changelog conflict and merged main in commit 4e2dbfe. Core and component tests, lint, and both package builds pass.

@mosch
mosch merged commit a3b8567 into main Sep 30, 2026
1 check passed
@mosch mosch mentioned this pull request Sep 30, 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.

Rotation Will Break the Crop Boundary Movement

2 participants