Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8c7023e
Vips: Add editImage for flip, rotate and crop edits
adamsilverstein Sep 2, 2026
00e6e2a
Upload media: Add an addEditedImage action
adamsilverstein Sep 2, 2026
c0b7c13
Media editor: Apply image edits client-side when available
adamsilverstein Sep 2, 2026
27938d9
Media: Record the source attachment of client-side image edits
adamsilverstein Sep 2, 2026
0e8b4df
Client-side media: Add e2e tests for image edits
adamsilverstein Sep 2, 2026
885120f
Add changelog entries for client-side image edits
adamsilverstein Sep 2, 2026
4f492db
Add backport changelog entry for the parent_image endpoint change
adamsilverstein Sep 2, 2026
2afe630
Upload media: Generate sub-sizes from the edited image
adamsilverstein Sep 3, 2026
6b333dd
Client-side media: Assert image-edit sub-sizes derive from the edited…
adamsilverstein Sep 3, 2026
ed895d7
Client-side media: Allow for browser-side processing in the modal rot…
adamsilverstein Sep 3, 2026
060009f
Media editor: Except the upload-media private API route
adamsilverstein Sep 3, 2026
8d2b90c
Media: Fire wp_edited_image_metadata for client-side edits
adamsilverstein Sep 3, 2026
2b31971
Image: Wait for the modal cropper to load before rotating in the e2e …
adamsilverstein Sep 3, 2026
b329564
Upload Media: Count image edits as image processing
adamsilverstein Sep 3, 2026
5aa1276
Merge remote-tracking branch 'origin/trunk' into try/csm-client-side-…
adamsilverstein Sep 8, 2026
2e7c4ad
Merge remote-tracking branch 'origin/trunk' into try/csm-client-side-…
adamsilverstein Sep 10, 2026
3cbefb4
Route images past the client memory budget to the server before editing
adamsilverstein Sep 10, 2026
310e116
Merge branch 'trunk' into try/csm-client-side-image-edits
adamsilverstein Sep 10, 2026
59b1629
Merge trunk into try/csm-client-side-image-edits
adamsilverstein Sep 15, 2026
c656520
Merge branch 'try/csm-client-side-image-edits' of github.com:WordPres…
adamsilverstein Sep 15, 2026
88bfae8
Merge remote-tracking branch 'origin/trunk' into try/csm-client-side-…
adamsilverstein Sep 16, 2026
a0cd9ad
Reformat for the Prettier and Markdown policy trunk now enforces
adamsilverstein Sep 16, 2026
1555584
Merge branch 'trunk' into try/csm-client-side-image-edits
adamsilverstein Nov 8, 2026
813c452
Fix client-side image edit tests after the trunk merge
adamsilverstein Nov 8, 2026
6f1f20a
Regenerate the vips README for editImage
adamsilverstein Nov 8, 2026
b5115c4
Update image edit e2e tests for trunk's media editor
adamsilverstein Nov 8, 2026
9c1c53f
Pick the aspect ratio from the docked Crop panel in e2e tests
adamsilverstein Nov 8, 2026
b27ffee
Find the aspect ratio option outside the modal's accessibility tree
adamsilverstein Nov 8, 2026
978256e
Match the theme's square aspect ratio preset in e2e tests
adamsilverstein Nov 8, 2026
2c4534b
Merge branch 'trunk' into try/csm-client-side-image-edits
adamsilverstein Nov 21, 2026
6dbdf5e
Merge branch 'trunk' into try/csm-client-side-image-edits
adamsilverstein Nov 23, 2026
cfe336e
Media Editor: Send post 0 when editing an unattached image
adamsilverstein Nov 23, 2026
7112467
Media Editor: Add e2e test for editing an unattached image
adamsilverstein Nov 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backport-changelog/7.2/13372.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/13372

* https://github.com/WordPress/gutenberg/pull/82362
92 changes: 92 additions & 0 deletions lib/media/class-gutenberg-rest-attachments-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,28 @@ public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CRE
);
}

return true;
},
);
$args['parent_image'] = array(
'type' => 'integer',
'minimum' => 1,
'description' => __( 'ID of the attachment the uploaded image was edited from. Recorded in the new attachment\'s metadata, as the edit endpoint does.', 'gutenberg' ),
'validate_callback' => static function ( $value, $request, $param ) {
// Re-apply the schema checks a custom validate_callback replaces.
$valid = rest_validate_request_arg( $value, $request, $param );
if ( is_wp_error( $valid ) ) {
return $valid;
}

if ( ! wp_attachment_is_image( (int) $value ) ) {
return new WP_Error(
'rest_invalid_param',
__( 'Invalid parent image.', 'gutenberg' ),
array( 'status' => 400 )
);
}

return true;
},
);
Expand All @@ -347,6 +369,15 @@ public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CRE
* @return true|WP_Error True if the request has access to create items, WP_Error object otherwise.
*/
public function create_item_permissions_check( $request ) {
// Recording an edit relation requires being allowed to edit the source, as the edit endpoint requires.
if ( ! empty( $request['parent_image'] ) && ! current_user_can( 'edit_post', (int) $request['parent_image'] ) ) {
return new WP_Error(
'rest_cannot_edit_image',
__( 'Sorry, you are not allowed to edit this image.', 'gutenberg' ),
array( 'status' => rest_authorization_required_code() )
);
}

$bypass_mime_check = false === $request['generate_sub_sizes'];

/*
Expand Down Expand Up @@ -429,6 +460,16 @@ public function create_item( $request ) {
if ( ! is_wp_error( $response ) ) {
$data = $response->get_data();
if ( ! empty( $data['id'] ) && wp_attachment_is_image( $data['id'] ) ) {
if ( ! empty( $request['parent_image'] ) ) {
$metadata = $this->record_parent_image( $data['id'], (int) $request['parent_image'] );
if ( isset( $data['media_details'] ) && is_array( $data['media_details'] ) ) {
$data['media_details']['parent_image'] = $metadata['parent_image'];
if ( isset( $metadata['image_meta'] ) ) {
$data['media_details']['image_meta'] = $metadata['image_meta'];
}
}
}

$mime_type = get_post_mime_type( $data['id'] );
$filename = get_attached_file( $data['id'] );

Expand Down Expand Up @@ -457,6 +498,57 @@ public function create_item( $request ) {
return $response;
}

/**
* Records the attachment an uploaded image was edited from.
*
* Mirrors what the edit endpoint stores for the attachment it creates, so an
* image edited in the browser relates to its source the same way: the
* `parent_image` entry, the source's EXIF data for any field the new file
* lacks, and an upright orientation, since the edited pixels are upright.
*
* @param int $attachment_id ID of the new attachment.
* @param int $parent_id ID of the attachment it was edited from.
* @return array The updated attachment metadata.
*/
private function record_parent_image( int $attachment_id, int $parent_id ): array {
$metadata = wp_get_attachment_metadata( $attachment_id );
if ( ! is_array( $metadata ) ) {
$metadata = array();
}

$parent_metadata = wp_get_attachment_metadata( $parent_id );
if ( isset( $parent_metadata['image_meta'] ) && is_array( $parent_metadata['image_meta'] ) ) {
if ( ! isset( $metadata['image_meta'] ) || ! is_array( $metadata['image_meta'] ) ) {
$metadata['image_meta'] = array();
}
// Merge but skip empty values, as the edit endpoint does.
foreach ( $parent_metadata['image_meta'] as $key => $value ) {
if ( empty( $metadata['image_meta'][ $key ] ) && ! empty( $value ) ) {
$metadata['image_meta'][ $key ] = $value;
}
}
}

if ( ! empty( $metadata['image_meta']['orientation'] ) ) {
$metadata['image_meta']['orientation'] = 1;
}

$parent_file = wp_get_original_image_path( $parent_id );

$metadata['parent_image'] = array(
Comment thread
adamsilverstein marked this conversation as resolved.
Resolved
'attachment_id' => $parent_id,
// Path to the originally uploaded image file relative to the uploads directory.
'file' => $parent_file ? _wp_relative_upload_path( $parent_file ) : '',
);

/** This filter is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */
$metadata = apply_filters( 'wp_edited_image_metadata', $metadata, $attachment_id, $parent_id ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound

wp_update_attachment_metadata( $attachment_id, $metadata );

return $metadata;
}

/**
* Sideloads an external image from a URL into the media library.
*
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/media-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Enhancements

- Apply crop, rotate and flip edits in the browser with client-side media processing when it is available, uploading the result through the upload queue so an UltraHDR gain map survives the edit, and fall back to the REST `media/<id>/edit` endpoint otherwise. An original the attachment record shows to be past the client memory budget goes straight to the server without being downloaded ([#82362](https://github.com/WordPress/gutenberg/pull/82362)).

## 0.23.0 (2026-11-18)

### Enhancements
Expand Down
1 change: 1 addition & 0 deletions packages/media-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"@wordpress/notices": "file:../notices",
"@wordpress/private-apis": "file:../private-apis",
"@wordpress/ui": "file:../ui",
"@wordpress/upload-media": "file:../upload-media",
"clsx": "^2.1.1",
"fast-deep-equal": "^3.1.3"
},
Expand Down
Loading
Loading