Skip to content

Commit

Permalink
Update image editor to use new REST API (#28530)
Browse files Browse the repository at this point in the history
* Update image editor to use new REST API

* Empty commit to start new Playwright tests
  • Loading branch information
Alex Lende authored May 4, 2023
1 parent 4409ba4 commit 44308e7
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down

0 comments on commit 44308e7

Please sign in to comment.