Skip to content

feat(crop-rotate): keep aspect ratio orientation on rotate#829

Merged
hm21 merged 2 commits into
stablefrom
feat/lock-aspect-ratio
Jun 14, 2026
Merged

feat(crop-rotate): keep aspect ratio orientation on rotate#829
hm21 merged 2 commits into
stablefrom
feat/lock-aspect-ratio

Conversation

@hm21

@hm21 hm21 commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #655.

Adds an opt-in flag CropRotateEditorConfigs.enableKeepAspectRatioOnRotate that keeps the crop frame's orientation when the image is rotated. With it enabled, a 9:16 crop stays 9:16 after a 90° rotation instead of inverting to 16:9, and the image is zoomed in so it still fully covers the crop area.

ProImageEditorConfigs(
  cropRotateEditor: CropRotateEditorConfigs(
    enableKeepAspectRatioOnRotate: true,
  ),
)
  • Works for fixed, original (0) and free (-1) aspect ratios — the current crop frame orientation is preserved by inverting its ratio.
  • Defaults to false, so existing behavior is unchanged (backward compatible, as requested in the issue).

How it works

  • The crop frame lives inside the rotating image transform, so letting it rotate would make a 9:16 frame visibly widen towards 1:1 at the 45° mark. To avoid this, during a locked rotation the crop overlay is faded out, the image rotates + zooms while the frame is hidden, and the frame is then faded back in at the preserved aspect ratio.
  • The target crop is computed by inverting the current crop ratio (calcCropRect(newRatio: …)), which keeps the on-screen orientation regardless of the ratio mode.
  • The rotation mechanics (angle, flipX/flipY, export cropRect) are unchanged, so cropping/export stay correct — no flip-swap changes were needed.

Changes

  • CropRotateEditorConfigs: new enableKeepAspectRatioOnRotate flag (+ copyWith).
  • CropRotateEditor: locked-rotation flow (fade out → rotate/zoom → fade in); only active when the flag is enabled, otherwise the normal rotate path is used.
  • CropCornerPainter: new frameOpacity multiplier to cleanly fade the crop overlay to transparent (the existing fadeInOpacity blends towards the background/hero state, which would hide the image outside the crop while rotating).

Tests

Added widget tests covering the enabled (fixed + free ratio) and disabled cases. flutter analyze is clean and all crop-rotate tests pass.

Add an opt-in `CropRotateEditorConfigs.enableKeepAspectRatioOnRotate`
flag that keeps the crop frame's orientation when the image is rotated,
so a `9:16` crop stays `9:16` instead of inverting to `16:9`. The image
is zoomed in to fully cover the crop area, and the crop overlay is faded
out/in during the rotation so the frame never appears to change its
aspect ratio mid-rotation.

Works for fixed, `original` and `free` aspect ratios. Defaults to
`false` to keep the existing behavior (backward compatible).

Closes #655
@hm21 hm21 force-pushed the feat/lock-aspect-ratio branch from 056caa0 to ffce5fb Compare June 14, 2026 09:27
@hm21 hm21 self-assigned this Jun 14, 2026
@hm21 hm21 merged commit 8765fd1 into stable Jun 14, 2026
1 check passed
@hm21 hm21 deleted the feat/lock-aspect-ratio branch June 14, 2026 09:30
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.

[Feature request] Add flag to prevent crop aspect ratio inversion on image rotation

1 participant