From 44308e7e0e657fa527efa7dd3a90514ce0b40f87 Mon Sep 17 00:00:00 2001 From: Alex Lende Date: Thu, 4 May 2023 04:56:58 -0500 Subject: [PATCH] Update image editor to use new REST API (#28530) * Update image editor to use new REST API * Empty commit to start new Playwright tests --- .../components/image-editor/use-save-image.js | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/block-editor/src/components/image-editor/use-save-image.js b/packages/block-editor/src/components/image-editor/use-save-image.js index 07c7aeed5e704..2d1515ff0e3f0 100644 --- a/packages/block-editor/src/components/image-editor/use-save-image.js +++ b/packages/block-editor/src/components/image-editor/use-save-image.js @@ -32,24 +32,35 @@ export default function useSaveImage( { const apply = useCallback( () => { setIsInProgress( true ); - let attrs = {}; + const modifiers = []; + + if ( rotation > 0 ) { + modifiers.push( { + type: 'rotate', + args: { + angle: rotation, + }, + } ); + } // The crop script may return some very small, sub-pixel values when the image was not cropped. // Crop only when the new size has changed by more than 0.1%. if ( crop.width < 99.9 || crop.height < 99.9 ) { - attrs = crop; - } - - if ( rotation > 0 ) { - attrs.rotation = rotation; + modifiers.push( { + type: 'crop', + args: { + left: crop.x, + top: crop.y, + width: crop.width, + height: crop.height, + }, + } ); } - attrs.src = url; - apiFetch( { path: `/wp/v2/media/${ id }/edit`, method: 'POST', - data: attrs, + data: { src: url, modifiers }, } ) .then( ( response ) => { onSaveImage( {