Skip to content

Image Cropper: Rebuild on the image editor and deprecate the package - #86407

Closed
ramonjd wants to merge 4 commits into
add/image-editor-max-zoomfrom
update/image-cropper-on-image-editor
Closed

ramonjd wants to merge 4 commits into
add/image-editor-max-zoomfrom
update/image-cropper-on-image-editor

Conversation

@ramonjd

@ramonjd ramonjd commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Note

The motivation behind this PR is to remove the react-easy-crop dependency and provide a crop experience that's close and won't break apps using the @wordpress/image-cropper package. Maybe we don't need to do this at all and just deprecate?

What?

Stacked on:

Follow-up to #86223, part of #86145.

Rebuilds @wordpress/image-cropper on @wordpress/image-editor behind its existing exports, drops react-easy-crop, and deprecates the package in favour of @wordpress/image-editor. Also adapts the deprecated inline image editor in @wordpress/block-editor, the package's only consumer in this repository.

Why?

The image editor README promised that the older cropper would be rebuilt on its maths and deprecated once it was. This removes a third-party dependency, leaves one set of cropping maths in the project, and keeps existing consumers of the package working while they move over.

How?

  • ImageCropper renders ImageEditorCanvas with a fixed crop box, the grid on and the size readout off. Its maxZoom prop reaches the hook through provider state, default 5.
  • ImageCropperProvider keeps the editor's state and derives the hook's old cropperState shape from it: croppedArea and croppedAreaPixels come from mapEditToOriginal, crop is the editor's pan. The reset state and isDirty are the provider's own, so the editor's public API did not change for them.
  • Whole quarter turns go through the editor's snap, which refits the crop to the largest box and turns the pan with the image, as the old cropper did. Fine angles use setRotation.
  • The package now ships build-style/style.css, which includes the image editor's stylesheet and removes the 22px handle gutter the wrapper has no use for. Consumers load it; the old library injected its own styles.
  • Mounting the provider logs a deprecation notice once. The since version is not set yet.
  • The block-editor inline editor rotates through the cropper instead of redrawing the image to a blob, drops the old library's class names from its stylesheet, and loads the cropper's stylesheet.

The differences a consumer of 2.x can notice are listed in the package CHANGELOG under Breaking Changes, and in the README under "Changes in 3.0".

Testing Instructions

  1. Open Storybook, "Editor/Image Cropper/ImageCropper", the "With Controls" story.
  2. Check the image fills its container edge to edge, with the rule-of-thirds grid over it.
  3. Rotate left and right. The view refits to the turned image; the crop keeps its ratio on screen.
  4. Flip, zoom with the slider and the wheel (zoom stops at 5), and change the aspect ratio. Reset returns to the start.
  5. Open the browser console. The deprecation notice naming @wordpress/image-editor appears once.

No core block renders the inline image editor since 7.1, so it can only be exercised by a plugin that renders wp.blockEditor.__experimentalImageEditor.

2026-11-06.13.44.28.mov
Screenshot 2026-11-06 at 1 46 54 pm

Follow-ups

  • Run npm deprecate on the package when this ships.
  • Move __experimentalImageEditor off the package, or remove it, before the package itself is removed.

Replace react-easy-crop with @wordpress/image-editor behind the same
exports: ImageCropper renders the editor canvas with a fixed crop box,
and the provider keeps the editor's state and derives the hook's old
shape from it. The reset state and dirtiness are the provider's own, so
the editor's public API does not change for this. Quarter turns go
through the editor's snap, which refits the crop and turns the pan with
the image as the old cropper did; fine angles use setRotation.

The package now ships a stylesheet, which includes the image editor's
and removes the handle gutter the wrapper has no use for. Mounting the
provider logs a deprecation notice naming @wordpress/image-editor. The
README and CHANGELOG list each difference a consumer of 2.x can see.

The deprecated inline image editor in block-editor keeps working: it
rotates through the cropper instead of redrawing the image to a blob,
drops the library's class names from its stylesheet, and loads the
cropper's stylesheet.
The rebuilt hook rebuilt its setters on every state change, because
they closed over the editor's controller. A consumer whose mount effect
depends on setResetState, as the README example does, would then call
it after every change and loop. The setters now reach the controller
and the reset snapshot through refs and keep one identity, as they did
before the rebuild. The canvas also shows the rule-of-thirds grid, which
the old library did by default.
@github-actions github-actions Bot added [Package] Block editor /packages/block-editor [Package] Image Cropper Related to packages/image-cropper labels Nov 6, 2026
@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🏷️ Labels

This pull request needs exactly one label indicating its type, and has 0.

  • Required: any label starting with [Type].
  • Found: none.

Read more about Type labels in Gutenberg. If you cannot add labels yourself, a reviewer can do it for you.

📦 Bundle size

Size Change: +11.5 kB (+0.13%)

Total Size: 8.62 MB

📦 View Changed
Filename Size Change
build/scripts/block-editor/index.min.js 553 kB +8.34 kB (+1.53%)
build/styles/block-editor/style-rtl.css 20.8 kB +848 B (+4.24%)
build/styles/block-editor/style-rtl.min.css 17.7 kB +730 B (+4.29%)
build/styles/block-editor/style.css 20.9 kB +858 B (+4.28%)
build/styles/block-editor/style.min.css 17.7 kB +714 B (+4.21%)

3708f22 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 7ca72e7 add/image-editor-max-zoom % Change
timeToFirstByte 32.65 ms +18.38% -3.06% 33.2 ms +10.69% -4.22% -1.66%
largestContentfulPaint 58 ms +10.34% -3.45% 60 ms +6.67% -6.67% -3.33%
lcpMinusTtfb 23.9 ms +10.67% -1.67% 24 ms +17.5% -5% -0.42%
wpBeforeTemplate 17.16 ms +13.29% -1.92% 17.16 ms +11.07% -2.62% 0%
wpTemplate 12.88 ms +4.43% -5.59% 12.95 ms +5.25% -4.94% -0.54%
wpTotal 29.87 ms +18.85% -3.05% 30.55 ms +10.93% -4.52% -2.23%
wpMemoryUsage 7.72 MB +0% -0% 7.71 MB +0% -0% 0.14%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 7ca72e7 add/image-editor-max-zoom % Change
timeToFirstByte 27.15 ms +8.1% -2.95% 27.6 ms +9.24% -3.26% -1.63%
largestContentfulPaint 64 ms +3.13% -3.13% 62 ms +3.23% -3.23% 3.23%
lcpMinusTtfb 36.5 ms +2.74% -7.12% 33.75 ms +4.44% -2.67% 8.15%
wpBeforeTemplate 15.15 ms +4.16% -1.12% 15.23 ms +9.52% -1.38% -0.53%
wpTemplate 9.49 ms +8.54% -3.58% 9.59 ms +7.19% -5.32% -1.04%
wpTotal 24.7 ms +8.83% -2.31% 25.07 ms +9.97% -2.63% -1.48%
wpMemoryUsage 6.41 MB +0% -0% 6.40 MB +0% -0% 0.16%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 7ca72e7 add/image-editor-max-zoom % Change
mediaProcessingJpeg 213.2 ms +3.14% -0.18% 216.04 ms +1.53% -1.94% -1.31%
mediaProcessingAvif 3515.3 ms +0.28% -0.39% 3549.81 ms +1.76% -0.66% -0.97%
mediaProcessingJpegToAvif 2449.54 ms +0.73% -0.23% 2478 ms +0.1% -0.04% -1.15%

media-upload

Metric 7ca72e7 add/image-editor-max-zoom % Change
jpegUploadProcessing 1387.21 ms +1.23% -1.08% 1402.82 ms +0.4% -0.95% -1.11%
pngUploadProcessing 176.67 ms +3.19% -8.76% 172.51 ms +7.75% -0.86% 2.41%
largeJpegUploadProcessing 1401.91 ms +1.1% -1.09% 1407.33 ms +0.64% -0.78% -0.39%
multipleImageUploadProcessing 1447.5 ms +0.4% -0.57% 1469.72 ms +0.76% -0.01% -1.51%

post-editor

Metric 7ca72e7 add/image-editor-max-zoom % Change
serverResponse 398.82 ms +0.59% -11.11% 377.18 ms +5.81% -4.49% 5.74%
firstPaint 316.29 ms +11.44% -21.66% 361.09 ms +29.13% -21.86% -12.41%
domContentLoaded 830.04 ms +2.07% -2.45% 818.54 ms +0.58% -2.1% 1.4%
loaded 831 ms +2.08% -2.44% 819.71 ms +0.57% -2.1% 1.38%
firstContentfulPaint 479.55 ms +3.07% -2.34% 469.08 ms +3.26% -0.96% 2.23%
firstBlock 1972.63 ms +2.81% -0.78% 2006.33 ms +0.57% -1.51% -1.68%
type 18.14 ms +5.95% -8.88% 17.31 ms +5.89% -10.46% 4.79%
typeWithoutInspector 16.55 ms +10.15% -4.65% 16.36 ms +9.05% -11.06% 1.16%
typeWithTopToolbar 22.37 ms +5.36% -9.75% 22.3 ms +6.68% -6.14% 0.31%
typeContainer 8.19 ms +16.36% -11.72% 8.55 ms +19.06% -10.99% -4.21%
focus 113.37 ms +5.33% -4.88% 109.55 ms +2.77% -3.89% 3.49%
firstFocus 245.04 ms +0% -0% 264.18 ms +0% -0% -7.25%
selectAll 323.07 ms +2.66% -0.41% 328.42 ms +1.57% -2.59% -1.63%
undo 29.38 ms +5.38% -5.28% 28.42 ms +4.75% -3.2% 3.38%
listViewOpen 72.87 ms +5.89% -6.52% 72.36 ms +12.92% -9.04% 0.7%
inserterOpen 39.29 ms +18.07% -7.66% 40.94 ms +1.91% -6.91% -4.03%
inserterHover 11.41 ms +5.08% -2.54% 10.68 ms +12.36% -5.15% 6.84%
inserterSearch 8.83 ms +8.15% -8.83% 8.95 ms +2.12% -8.16% -1.34%
loadPatterns 630.71 ms +3.98% -5.18% 630.13 ms +2.36% -7.78% 0.09%
wpTotal 388.68 ms +0.77% -11.31% 367.51 ms +5.96% -4.61% 5.76%
wpMemoryUsage 14.76 MB +0% -0% 14.74 MB +0% -0% 0.19%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 7ca72e7 add/image-editor-max-zoom % Change
serverResponse 406.12 ms +5.77% -6.7% 413.7 ms +6% -6.42% -1.83%
firstPaint 393.38 ms +8.53% -5.98% 401.88 ms +32.87% -9.47% -2.12%
domContentLoaded 920.67 ms +2.49% -2.1% 939.63 ms +1.1% -1.1% -2.02%
loaded 921.64 ms +2.51% -2.07% 940.45 ms +1.11% -1.07% -2%
firstContentfulPaint 536.49 ms +3.22% -2.04% 542.39 ms +2.28% -1.55% -1.09%
firstBlock 2640.98 ms +2.53% -0.82% 2703.63 ms +0.44% -0.48% -2.32%
type 20.63 ms +2.28% -3.44% 24.27 ms +4.04% -12.36% -15%
navigate 125.21 ms +13.26% -9.18% 134.51 ms +11.88% -4% -6.91%
loadPatterns 1661.56 ms +8.79% -15.73% 1637.37 ms +8.28% -12.99% 1.48%
loadPages 1027.1 ms +1.78% -3.48% 1018.13 ms +0.99% -3.79% 0.88%
wpTotal 395.14 ms +5.78% -6.9% 402.39 ms +6.18% -6.54% -1.8%
wpMemoryUsage 12.78 MB +0% -0% 12.77 MB +0% -0% 0.06%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

3708f22 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Undo restores the post selection when another synced entity is loaded (RTC WebSocket) in /test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

  Object {
    "attributeKey": "content",
    "blockIndex": 0,
    "content": "abcdef",
-   "endOffset": 3,
-   "offset": 3,
+   "endOffset": 6,
+   "offset": 6,
  }

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-undo-redo.spec.ts:363:5
moves selected text within a paragraph in /test/e2e/specs/editor/various/draggable-blocks.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 1
+ Received  + 1

  Array [
    Object {
      "attributes": Object {
-       "content": "second First third",
+       "content": "First second third",
      },
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/draggable-blocks.spec.js:1209:41
should select by dragging in /test/e2e/specs/editor/various/multi-block-selection.spec.js, passed after 1 failed attempt.
Error: expect(received).toEqual(expected) // deep equality

- Expected  - 1
+ Received  + 0

  Array [
    1,
-   2,
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/multi-block-selection.spec.js:533:5

3708f22 Run

@github-actions github-actions Bot added the [Package] Image Editor Related to packages/image-editor label Nov 6, 2026
…wap, and getCroppedImage's source

Three fixes from review:

- The editor's snap reverses the stored rotation's direction when
  exactly one axis is flipped, so a requested rotation of 90 landed on
  270. The hook now picks the snap direction from the flip, so the
  stored value is the number asked for.
- Replacing the loaded image left the reset snapshot describing the old
  one, so isDirty compared the wrong images and reset applied the old
  pan and zoom to the new picture. The reset state is applied to the
  new image and the snapshot is taken again from the result.
- getCroppedImage honours its src argument again, as the image to cut
  from, instead of ignoring it. The changelog, README and plan no longer
  list that deviation.
@ramonjd

ramonjd commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

Closing in favour of deprecating the package in place: #86417.

@ramonjd ramonjd closed this Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Package] Image Cropper Related to packages/image-cropper [Package] Image Editor Related to packages/image-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant