Skip to content

Client-side media: Process image edits (crop, rotate, flip) with wasm-vips - #82362

Open
adamsilverstein wants to merge 30 commits into
trunkfrom
try/csm-client-side-image-edits
Open

adamsilverstein wants to merge 30 commits into
trunkfrom
try/csm-client-side-image-edits

Conversation

@adamsilverstein

@adamsilverstein adamsilverstein commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Claude Code wrote this description from the branch, forwarded along:

What?

Process image edits (crop, rotate, flip) made in the media editor modal in the browser with wasm-vips, and upload the result through the client-side media upload queue, instead of POSTing the modifiers to the server-side media/<id>/edit endpoint. The server path stays as the fallback whenever client-side processing is unavailable.

Fixes #82358
Fixes #82295

Why?

Uploads already run through libvips in the browser, but edits still went through GD/ImageMagick on the server. That mismatch is what strips the gain map from an HDR JPEG when it is cropped or rotated (#82295). GD and ImageMagick are gaining gain map support behind build flags, which will take a long time to reach most hosts; libvips ships with client-side media today.

How?

Following the sketch in #82358, with the same design decisions:

  • @wordpress/vips gains editImage( id, buffer, type, modifiers ), a single helper that turns the /edit endpoint's modifiers array into vips operations. It mirrors WP_REST_Attachments_Controller::edit_media_item(): any pending EXIF orientation is applied first so edits run in the upright frame the user previewed, then flip, rotate and crop are applied in order. Right angles use the exact rot90/rot180/rot270, other angles go through rotate onto the rotated bounding box, and crop percentages refer to whatever frame the crop is applied to, rounded the way core rounds them. For UltraHDR JPEGs the gain map is transformed in step with the base image (libvips leaves it untouched otherwise), so it survives the edit. The full-size result keeps its metadata, like core's edited file does.
  • @wordpress/upload-media gains a public addEditedImage action and an EditImage queue operation that runs ahead of Prepare. The edited file then goes through the regular pipeline, so sub-sizes are generated client-side (and keep the gain map too) and the result is a new attachment, matching how the editor has always created edited images. The file is named <basename>-edited.<ext> like the server does, without stacking the suffix on re-edits. If the edit step itself fails, onError gets an IMAGE_EDIT_ERROR before anything reaches the server.
  • @wordpress/media-editor's save hook now fetches the attachment's original file (the unscaled one when a -scaled copy exists), runs the edit through the queue and, on success, resolves the finalized attachment record. Title, caption, description, alt text and the parent post are carried across like the /edit endpoint does, with pending Details-tab edits taking precedence. Anything that stops the client-side path before upload (no browser support, queue not wired to a server transport, fetch failure, a format vips cannot write) falls back to the existing /edit request. Undo works as before: the block is pointed back at the previous id/url.
  • The media create endpoint (lib/media/class-gutenberg-rest-attachments-controller.php) gains a parent_image parameter, which the media editor sends with the upload. When set it must be an image attachment the user can edit, and the new attachment gets what edit_media_item() records for its own new attachment: the parent_image metadata entry, the source's EXIF image_meta for fields the new file lacks, and an upright orientation. Core companion: REST API: Record the source attachment of an uploaded image edit. wordpress-develop#13372 (https://core.trac.wordpress.org/ticket/66027).

Not covered here

  • The legacy __experimentalImageEditor in @wordpress/block-editor (use-save-image.js) still calls editMediaEntity. Core blocks now use the media editor modal, so it is left on the server path in this PR; it could reuse addEditedImage in a follow-up.
  • The standalone media editor page (routes/media-editor) has no block editor provider wiring up the upload queue, so it keeps using /edit for now.

Testing Instructions

Test in WordPress Playground

Client-side media processing needs to be active (Gutenberg experiment enabled, Chrome or Firefox).

  1. Add an Image block and upload test/e2e/assets/1024x768_e2e_test_image_ultrahdr.jpeg (an UltraHDR JPEG with a gain map).
  2. Open the network panel, then click "Edit image" in the block toolbar.
  3. Rotate 90° clockwise and save. The block switches to a new attachment; there is no request to /wp/v2/media/<id>/edit, only a POST /wp/v2/media, sub-size sideloads and a finalize request.
  4. Download the edited full-size file and check it still has its gain map, e.g. with exiftool (look for the MPF/gain map segments) or by viewing it in an HDR-capable browser on an HDR display. Sub-sizes keep it too.
  5. Try a crop (pick an aspect ratio, or drag the stencil), a flip, and a fine rotation, and confirm the result matches the preview. Try undo from the snackbar.
  6. Edit an already-edited image: the new file is still ...-edited-N.jpg, not ...-edited-edited.jpg.
  7. Edit an image whose title, caption, alt text or attached post differ from the defaults, with and without changing them in the Details tab, and confirm the new attachment carries them. Its media_details.parent_image in the REST response points at the source attachment.
  8. With the experiment disabled (or in Safari), editing still works through the server /edit endpoint as before.

Automated tests

  • packages/vips/src/test/edit-image.ts covers the modifier to operation mapping, and edit-image-integration.ts runs the real wasm-vips build to confirm rotation direction (clockwise for a positive angle, as core expects), the crop frame after a rotation, EXIF-first handling and gain map preservation.
  • client-side-media-processing.spec.js gains e2e tests that rotate and crop the UltraHDR fixture through the modal and assert the gain map survives on the full-size file and the sub-sizes, that the new attachment records its source, and that no /edit request is made. Both fail against trunk (/edit called) and pass with this branch.
  • PHPUnit covers the parent_image parameter: recorded metadata and response, the no-parameter case, a non-image parent (400) and an author who cannot edit the source (403).

Types of changes

  • Add editImage to @wordpress/vips and expose it from the worker.
  • Add addEditedImage action and EditImage operation to @wordpress/upload-media.
  • Route the media editor modal's save through the queue when client-side media is available, fall back to /edit otherwise.
  • Add a parent_image parameter to the media create endpoint (with a core companion PR).
  • Add unit, integration and e2e tests, changelog entries.

AI Use

Code and description both written with 🤖 Claude Code, working from the plan in #82358. I will review and test.

Summary by CodeRabbit

  • New Features
    • Added client-side cropping, rotating, and flipping before upload.
    • Preserves image metadata, EXIF orientation, and UltraHDR gain maps during edits.
    • Tracks source images and inherits relevant metadata for edited attachments.
    • Uses server-side processing when client-side editing is unavailable or fails.
  • Bug Fixes
    • Added clearer errors for unsupported files and image-editing failures.
  • Documentation
    • Documented image-editing and upload capabilities.

Applies the REST /edit endpoint's modifiers with libvips so image edits
can run in the browser. EXIF orientation is applied first, matching the
frame the user previewed, and an UltraHDR gain map is transformed in step
with the base image instead of being dropped.
Queues an image edit ahead of the regular upload pipeline so the edited
file is uploaded as a new attachment with client-side sub-sizes. A
failing edit is reported with IMAGE_EDIT_ERROR before anything reaches
the server, so callers can fall back to the /edit endpoint.
Fetch the original file, apply crop, rotate and flip with vips and
upload the result through the upload queue, falling back to the server
/edit endpoint when client-side processing is unavailable. Keeps HDR
gain maps that the server-side editors strip (#82295).
@adamsilverstein adamsilverstein added [Type] Enhancement A suggestion for improvement. [Feature] Media Anything that impacts the experience of managing media [Feature] Client Side Media Media processing in the browser with WASM labels Sep 2, 2026
@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 7bc04ac8-d83c-4096-9217-20628458fcc5

📥 Commits

Reviewing files that changed from the base of the PR and between 2b31971 and b329564.

📒 Files selected for processing (4)
  • packages/upload-media/src/store/actions.ts
  • packages/upload-media/src/store/private-actions.ts
  • packages/upload-media/src/store/private-selectors.ts
  • packages/upload-media/src/store/test/selectors.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/upload-media/src/store/actions.ts
  • packages/upload-media/src/store/private-actions.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

This change adds client-side crop, rotate, and flip processing through wasm-vips. Edited files use the upload queue, preserve UltraHDR gain maps, create linked attachments, and fall back to the REST edit endpoint when client-side processing is unavailable.

Changes

Client-side image editing

Layer / File(s) Summary
VIPS image-editing engine
packages/vips/src/*, packages/vips/README.md, packages/vips/CHANGELOG.md
Adds typed flip, rotate, and crop modifiers. VIPS applies ordered edits, normalizes EXIF orientation, preserves metadata, and transforms UltraHDR gain maps.
Upload-queue edit operation
packages/upload-media/src/*, packages/upload-media/README.md, packages/upload-media/CHANGELOG.md
Adds addEditedImage, the EDIT_IMAGE operation, VIPS processing, filename normalization, validation, callbacks, and IMAGE_EDIT_ERROR handling.
Media editor client-side workflow
packages/media-editor/src/*, packages/media-editor/package.json, packages/media-editor/tsconfig*.json, packages/media-editor/CHANGELOG.md, tools/validation/*
The media editor fetches the original image, submits client-side edits through the upload queue, preserves attachment metadata, and falls back to /edit.
Attachment metadata and end-to-end validation
lib/media/*, phpunit/media/*, test/e2e/specs/editor/*, backport-changelog/*
Attachment creation accepts parent_image, checks permissions, records inherited metadata, and exposes the relationship. Unit, integration, and E2E tests cover edits, gain maps, and re-editing.

Estimated code review effort: 5 (Critical) | ~90 minutes

Merge Risk: ⚪ Minimal · up to b3295

Edited-image queue work is covered by the reviewed selector tests, with no outstanding issue identified for this change.

Sequence Diagram(s)

sequenceDiagram
  participant MediaEditor
  participant EditImageClientSide
  participant UploadMedia
  participant VipsWorker
  participant AttachmentsController
  MediaEditor->>EditImageClientSide: Submit original file and modifiers
  EditImageClientSide->>UploadMedia: Enqueue edited attachment
  UploadMedia->>VipsWorker: Process image modifiers
  VipsWorker-->>UploadMedia: Return edited file and dimensions
  UploadMedia->>AttachmentsController: Create attachment with parent_image
  AttachmentsController-->>UploadMedia: Return finalized attachment
  UploadMedia-->>MediaEditor: Return attachment ID
Loading

Suggested reviewers: ciampo

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the primary change: client-side crop, rotate, and flip processing with wasm-vips.
Linked Issues check ✅ Passed The changes satisfy the linked objectives [#82358] [#82295]. They add wasm-vips editing, client-side upload-queue integration, sub-size generation, server fallback, attachment lineage metadata, UltraH…
Out of Scope Changes check ✅ Passed The implementation, metadata handling, documentation, configuration, tests, and changelog entries directly support the linked image-editing and gain-map objectives. No unrelated code changes are evide…
Docstring Coverage ✅ Passed Docstring coverage is 93.75% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 48 functions across 25 files.
Full details: Linked Issues check

Explanation

The changes satisfy the linked objectives [#82358] [#82295]. They add wasm-vips editing, client-side upload-queue integration, sub-size generation, server fallback, attachment lineage metadata, UltraHDR gain-map preservation, undo-compatible replacement attachments, and broad automated coverage.

Full details: Out of Scope Changes check

Explanation

The implementation, metadata handling, documentation, configuration, tests, and changelog entries directly support the linked image-editing and gain-map objectives. No unrelated code changes are evident.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch try/csm-client-side-image-edits

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/upload-media/src/store/actions.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/upload-media/src/store/private-actions.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

packages/upload-media/src/store/private-selectors.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

  • 1 others

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

🎉 Props

Unlinked Accounts

The following contributors have not linked their GitHub and WordPress.org accounts: @t-wright.

Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Unlinked contributors: t-wright.

Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Co-authored-by: gregbenz <gregbenz@git.wordpress.org>
Co-authored-by: swissspidy <swissspidy@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +2.65 kB (+0.03%)

Total Size: 8.69 MB

📦 View Changed
Filename Size Change
build/modules/vips/worker.min.js 3.79 MB +1.62 kB (+0.04%)
build/scripts/editor/index.min.js 573 kB +608 B (+0.11%)
build/scripts/upload-media/index.min.js 16.5 kB +427 B (+2.66%)

2c4534b Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 0d45c54 trunk % Change
timeToFirstByte 42.95 ms +9.66% -3.03% 43.5 ms +7.01% -3.91% -1.26%
largestContentfulPaint 70 ms +2.86% -2.86% 68 ms +5.88% -2.94% 2.94%
lcpMinusTtfb 24.7 ms +25.1% -8.1% 24 ms +19.17% -7.08% 2.92%
wpBeforeTemplate 22.13 ms +17.62% -1.81% 22.34 ms +15.76% -2.64% -0.94%
wpTemplate 17.23 ms +2.79% -4.29% 17.07 ms +3.69% -3.57% 0.94%
wpTotal 39.45 ms +10.39% -2.53% 40.19 ms +7.07% -3.88% -1.84%
wpMemoryUsage 7.75 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 0d45c54 trunk % Change
timeToFirstByte 35.45 ms +9.87% -3.1% 35.25 ms +4.96% -2.98% 0.57%
largestContentfulPaint 64 ms +3.13% -3.13% 64 ms +0% -6.25% 0%
lcpMinusTtfb 28.35 ms +1.94% -7.94% 27 ms +6.85% -3.89% 5%
wpBeforeTemplate 19.41 ms +10.25% -1.49% 19.25 ms +1.14% -2.08% 0.83%
wpTemplate 13.32 ms +6.46% -4.8% 12.64 ms +6.88% -3.4% 5.38%
wpTotal 32.73 ms +10.24% -2.32% 32.5 ms +3.51% -3.08% 0.71%
wpMemoryUsage 6.44 MB +0% -0% 6.40 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 0d45c54 trunk % Change
mediaProcessingJpeg 325.5 ms +0.61% -0.9% 326.42 ms +0.59% -0.59% -0.28%
mediaProcessingAvif 4867.91 ms +0.28% -0.29% 4824.74 ms +0.39% -0.16% 0.89%
mediaProcessingJpegToAvif 3379 ms +0.35% -0.13% 3382.3 ms +0.12% -0.5% -0.1%

media-upload

Metric 0d45c54 trunk % Change
jpegUploadProcessing 1464.99 ms +0.8% -2.12% 1456.28 ms +0.68% -0.43% 0.6%
pngUploadProcessing 232.55 ms +10% -5.66% 242.3 ms +5.91% -3.04% -4.02%
largeJpegUploadProcessing 1440.64 ms +0.31% -0.34% 1432.63 ms +1.25% -0.31% 0.56%
multipleImageUploadProcessing 1522.1 ms +0.67% -2.64% 1517.49 ms +1.61% -0.83% 0.3%

post-editor

Metric 0d45c54 trunk % Change
serverResponse 446.88 ms +6.19% -2.35% 444.08 ms +9.01% -3.98% 0.63%
firstPaint 439.92 ms +9.7% -7.45% 414.15 ms +8.76% -7.16% 6.22%
domContentLoaded 824.95 ms +9.32% -2% 811.28 ms +1.73% -1.69% 1.68%
loaded 826.1 ms +9.31% -2.01% 812.44 ms +1.69% -1.71% 1.68%
firstContentfulPaint 469.97 ms +12.32% -5.27% 459.61 ms +0.76% -2.02% 2.25%
firstBlock 2229.95 ms +1.53% -1.55% 2196.51 ms +0.76% -0.65% 1.52%
type 16.98 ms +6.42% -6.12% 16.93 ms +6.73% -5.38% 0.3%
typeWithoutInspector 15.81 ms +12.84% -3.54% 16.96 ms +6.96% -9.08% -6.78%
typeWithTopToolbar 22.83 ms +3.24% -6.96% 22.32 ms +6.41% -9.9% 2.28%
typeContainer 8.35 ms +5.99% -14.61% 7.96 ms +4.27% -13.69% 4.9%
focus 124.27 ms +2.9% -7.24% 120.74 ms +0.98% -13.29% 2.92%
firstFocus 268.52 ms +0% -0% 257.13 ms +0% -0% 4.43%
selectAll 393.79 ms +5.46% -4.28% 408.96 ms +6% -4.35% -3.71%
undo 28.55 ms +7.18% -6.37% 29.43 ms +2.99% -8.22% -2.99%
listViewOpen 79.71 ms +11.28% -10.86% 75.05 ms +10.53% -4.4% 6.21%
inserterOpen 41.28 ms +3.51% -3.9% 39.18 ms +12.69% -3.83% 5.36%
inserterHover 11.41 ms +12.71% -7.19% 10.77 ms +9.66% -11.05% 5.94%
inserterSearch 8.19 ms +5.62% -6.84% 7.6 ms +19.87% -4.47% 7.76%
loadPatterns 622.26 ms +3.98% -1.29% 638.48 ms +6.43% -3.64% -2.54%
wpTotal 437.07 ms +6.3% -2.37% 434.25 ms +9.23% -4.06% 0.65%
wpMemoryUsage 14.81 MB +0% -0% 14.77 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 0d45c54 trunk % Change
serverResponse 397.53 ms +1.28% -6.67% 392.68 ms +2.88% -4.59% 1.24%
firstPaint 403.52 ms +9.94% -7.96% 435.48 ms +2.03% -10.68% -7.34%
domContentLoaded 795.93 ms +5.06% -1.77% 788.57 ms +1.15% -0.89% 0.93%
loaded 796.83 ms +5.06% -1.77% 789.47 ms +1.15% -0.91% 0.93%
firstContentfulPaint 443.18 ms +11.53% -1.44% 440.16 ms +2.11% -1.09% 0.69%
firstBlock 2399.88 ms +2.77% -1.68% 2366.94 ms +0.72% -0.89% 1.39%
type 16.17 ms +12.49% -7.36% 16.06 ms +10.09% -4.73% 0.68%
navigate 101.15 ms +6.6% -1.1% 107.45 ms +3.83% -3.95% -5.86%
loadPatterns 1236.12 ms +3.81% -1.05% 1203.48 ms +13.74% -14.68% 2.71%
loadPages 915.08 ms +0.51% -1.13% 910.04 ms +5.25% -0.48% 0.55%
wpTotal 388.63 ms +1.21% -6.86% 383.58 ms +2.95% -4.68% 1.32%
wpMemoryUsage 12.84 MB +0% -0% 12.80 MB +0% -0% 0.29%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

2c4534b 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.

does not select blocks in the canvas preview when editing from the sidebar (Site Editor v2) in /test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js, passed after 1 failed attempt.
Error: expect(locator).toBeFocused() failed

Locator: getByRole('combobox', { name: 'Search or type URL' })
Expected: focused
Timeout: 5000ms
Error: element(s) not found

Call log:
  - Expect "toBeFocused" getByRole('combobox', { name: 'Search or type URL' }) with timeout 5000ms
  - waiting for getByRole('combobox', { name: 'Search or type URL' })

    at LinkControl.useLinkControlSearch (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:416:47)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-sidebar-list-view.spec.js:179:21
should arrow up into empty columns in /test/e2e/specs/editor/blocks/columns.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 0
+ Received  + 7

@@ -1,9 +1,16 @@
  Array [
    Object {
      "innerBlocks": Array [
        Object {
+         "attributes": Object {},
+         "innerBlocks": Array [],
+         "name": "core/column",
+       },
+       Object {
+         "attributes": Object {},
+         "innerBlocks": Array [],
          "name": "core/column",
        },
      ],
      "name": "core/columns",
    },

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/columns.spec.js:349:41

2c4534b Run

Add a parent_image parameter to the media create endpoint so an image
edited in the browser relates to its source the way the /edit endpoint's
new attachment does: the parent_image metadata entry, the source's EXIF
fields the new file lacks, and an upright orientation. The media editor
passes the edited attachment's ID along with the upload.
Rotate and crop an UltraHDR image through the media editor modal and
check that no /edit request is made, that the gain map survives on the
full-size file and its sub-sizes, and that the new attachment carries
the source's details and parent_image relation.
@andrewserong

andrewserong commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Thanks so much for getting this started! Just cross-linking this to the WIP PR to track the original attachment id for crops over in #81803 as it's an overlapping area that @ramonjd has been looking into. It seems for both of these features (restore original is the other feature) we'll need to track the relationship of the new attachment back to the original attachment the crop was performed from. So, hopefully we can find a good shape that serves both purposes.

Excited to see the client-side media stuff roll out to the media editor! 🎉

The edit step replaced the queue item's file but left sourceFile, which
generateThumbnails reads, pointing at the un-edited original. Sub-sizes of
an edited image were therefore made from the source attachment, one edit
behind the full-size file. Replace sourceFile with the edited file too.

See #82295 (comment)
… image

Compare each sub-size's pixels against the region of the edited full-size
image it is resized or centre-cropped from, so a sub-size made from the
source attachment fails even when its dimensions match (a flip). Cover
rotate, flip, crop and a second edit of an edited image, each checking the
gain map on every size.
@adamsilverstein

Copy link
Copy Markdown
Member Author

Greg's Playground testing over on #82295 (comment) turned up a real bug: the full size was edited correctly but every sub-size was one edit behind. Fixed in 2afe630, with e2e coverage in 6b333dd.

Claude tracked this one down, here is the write up:

The edit step in the upload queue replaced the item's file with the edited image but left sourceFile untouched, and generateThumbnails builds every sub-size from sourceFile. So the sub-sizes were always made from the un-edited original, which is exactly why a second edit showed the first edit in the smaller sizes. The fix sets sourceFile to the edited file as well.

The existing e2e tests missed it because they compared each sub-size's decoded dimensions with the dimensions the server registered for it, and those agree with each other whichever file the sub-size came from.

The new tests cover rotate, flip, crop, and a crop followed by a flip of the edited attachment. For every registered size they check that the gain map is present, that the dimensions match, and that the pixels match the region of the edited full-size image the size is resized or centre-cropped from. The fixture has a different colour in each corner, so a flipped full size with un-flipped sub-sizes fails even though the dimensions are identical. All four failed against the previous build for the reason Greg described and pass with the fix.

Manual check: a Playwright run against wp-env uploaded the UltraHDR fixture, applied each edit in the modal and rendered the full size plus every sub-size as served, with exiftool output (NumberOfImages: 2 and the MPImage2 blob are the gain map). No requests to /wp/v2/media/<id>/edit in any run.

Rotate 90° clockwise, before the fix - thumbnail and medium are still landscape:

Rotate before fix

Rotate 90° clockwise, after the fix:

Rotate after fix

Crop to square, after the fix (medium is now 300×300):

Crop after fix

Flip horizontal, after the fix (same dimensions, mirrored pixels on every size):

Flip after fix

The media editor modal with the rotation applied, before saving:

Edit media modal

@gregbenz whenever you have a chance, can you please re-test in Playground once the build for the new commits lands? https://playground.wordpress.net/gutenberg.html?pr=82362

@gregbenz

gregbenz commented Sep 3, 2026

Copy link
Copy Markdown

@adamsilverstein Just tested https://playground.wordpress.net/gutenberg.html?pr=82362

Test #1: Dragged 2 JPG gain maps at same time into post. Immediately selected and changed resolution to "thumbnail" on one and then "medium" to the other. The preview of the assets stayed the same, but the small size showed low quality - suggesting that it was loading the smaller assets but scaling all to the same size on screen.

Test #2: Selected one to edit with crop, flip, and rotate 90 degrees. Result was still HDR at all sizes. However, I saw the wrong part of the image, not the same area I was viewing while cropping. I assume this is probably a manifestation of the first finding.

Test #3: deleted those images and uploaded a single (one of the same previous, just not two at same time). Changing resolution worked. Crop, flip, rotate worked and immediately showed the correct size / result.

Test #4: repeated #1 and saw same results. Uploading two images at the same time seems to be a problem.

…ate test

Saving through the media editor modal now applies the edit and generates
sub-sizes in the browser when client-side media processing is available,
so closing the modal takes longer than the default expectation timeout.
The media editor now dispatches the upload queue's addEditedImage action,
which pulls the upload-media store and its lock-unlock into the graph.
Pass the metadata recorded for a client-side edit through the same filter
core fires for the edit endpoint's new attachment, so hooks such as the
original attachment lineage see edits made in the browser too.
@gregbenz

gregbenz commented Sep 8, 2026

Copy link
Copy Markdown

@adamsilverstein FYI that I am proposing upstream improvements in wasm-vips so that flips/rotations work by default. I believe moving upstream has the most benefit so that other users of that library benefit (and I could not find any examples of downstream use that would break, which makes sense for such a transform with a new capability).

If that PR is accepted by wasm-vips, I'll provide an update here. At that time, I would be happy to help suggest changes or create an updated PR for WordPress (doing so will simplify this PR and will improve performance by avoiding a safe but wasteful extra flip/rotation calculation).

@adamsilverstein

Copy link
Copy Markdown
Member Author

@adamsilverstein FYI that I am proposing upstream improvements in wasm-vips so that flips/rotations work by default. I believe moving upstream has the most benefit so that other users of that library benefit (and I could not find any examples of downstream use that would break, which makes sense for such a transform with a new capability).

Great idea, thanks @gregbenz!

…image-edits

# Conflicts:
#	packages/upload-media/src/store/test/vips.jsdom.test.ts
@gregbenz

Copy link
Copy Markdown

@adamsilverstein Quick update: wasm-vips declined the PR with their intention being to keep it a thin wrapper around libvips (ie wrong level to target the change, I'm evaluating).

adamsilverstein and others added 5 commits September 10, 2026 08:41
…image-edits

# Conflicts:
#	packages/media-editor/CHANGELOG.md
#	packages/upload-media/CHANGELOG.md
#	packages/vips/CHANGELOG.md
The edit operation ran ahead of prepareItem's large-image gate, so an
image too big for the wasm-vips memory cap was downloaded and decoded
before anything caught it. Check the file header in editImageItem and
fail with IMAGE_EDIT_ERROR so the media editor falls back to /edit, and
skip the download altogether when the attachment record already shows
the original is too large. The record's dimensions describe the scaled
copy once the big image threshold applies, so that pre-check only
trusts a record without original_image.

Suggested by ramonjd in review.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ExwaM5APhmA5u75pBjyuLt
…s/gutenberg into try/csm-client-side-image-edits
adamsilverstein and others added 2 commits September 16, 2026 15:31
…image-edits

# Conflicts:
#	packages/upload-media/CHANGELOG.md
The trunk merge brought Prettier 3.9.6 and the new Markdown list style;
reformat the one JS callsite and regenerate the two package READMEs so
the branch matches what a clean CI install produces.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RtZdDWdC33cNHfY4U238A5
Type the editImageItem tests merged into the TypeScript private actions
tests, and use a larger image for the too-large checks now that trunk
raised the client memory budgets (#84980).
Trunk moved the cropper to @wordpress/image-editor and replaced the
Reset button and aspect ratio select with a History menu and an aspect
ratio menu, so wait on the new loaded class and drive the new controls.
@ramonjd

ramonjd commented Nov 12, 2026

Copy link
Copy Markdown
Member

I haven't forgotten this one, sorry! I've been working on getting the core image editor API into its own package.

You'll have been seeing the conflicts 😄

Once it's done we can see how things might fit there. Cheers!

@adamsilverstein

Copy link
Copy Markdown
Member Author

I haven't forgotten this one, sorry! I've been working on getting the core image editor API into its own package.

Excellent - thanks for the update @ramonjd!

t-wright added a commit to Automattic/jetpack that referenced this pull request Nov 20, 2026
Client-side media processing (WordPress/gutenberg#82362) edits images in the browser and uploads the result with a parent_image. The browser keeps the source's XMP but drops its C2PA manifest, so editing an image marked only in C2PA, such as a GPT image, would lose the marker. A wp_edited_image_metadata hook now writes the source's type into the edited file when it has none, and logs the changed file again on Simple so file storage gets it.

Jetpack_WPCOM_AI_Marker caches each source's type for the request, so on core's server edit path the hook reuses the editor's read instead of downloading the original again.
}
const post =
pendingEdits && 'post' in pendingEdits ? pendingEdits.post : media.post;
if ( post !== undefined ) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noticed while testing that editing an unattached image returns a 400 (post is not of type integer), because media.post is null.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Client Side Media Media processing in the browser with WASM [Feature] Media Anything that impacts the experience of managing media [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement.

Projects

None yet

5 participants