Make WordPress Core

Changeset 58612

Timestamp:
07/01/2024 08:43:55 PM (5 weeks ago)
Author:
SergeyBiryukov
Message:

REST API: Correct image cropping tools in the block editor.

As of [58457], the width and height cropping values are cast to an integer before the comparison to see if the target width and height differ from the original width and height.

Since they are now integers, it exposes a bug where the && of the if conditional meant that if you were only cropping in one dimension, the check wouldn't pass, and cropping would not occur.

In the block editor, the cropping tools are aspect ratio based, so one of the dimensions will always match that of the source image. Therefore, now that the values are cast as integers, the condition that allows a cropping to occur needs to be updated. If either width or height is different from the source image, then a crop should be allowed.

Follow-up to [50124], [58457].

Props andrewserong, jrf, kevin940726.
Fixes #61514. See #59782.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r58457 r58612  
    627627                    $height = (int) round( ( $size['height'] * $args['height'] ) / 100.0 );
    628628
    629                     if ( $size['width'] !== $width && $size['height'] !== $height ) {
     629                    if ( $size['width'] !== $width $size['height'] !== $height ) {
    630630                        $result = $image_editor->crop( $crop_x, $crop_y, $width, $height );
    631631
  • trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r58457 r58612  
    23832383
    23842384    /**
     2385
     2386
     2387
     2388
     2389
     2390
     2391
     2392
     2393
     2394
     2395
     2396
     2397
     2398
     2399
     2400
     2401
     2402
     2403
     2404
     2405
     2406
     2407
     2408
     2409
     2410
     2411
     2412
     2413
     2414
     2415
     2416
     2417
     2418
     2419
     2420
     2421
    23852422     * @ticket 44405
    23862423     * @requires function imagejpeg
Note: See TracChangeset for help on using the changeset viewer.