Make WordPress Core

Changeset 58457

Timestamp:
06/21/2024 08:35:25 PM (4 weeks ago)
Author:
joedolson
Message:

Media: Fix implicit conversion from float to int in image cropping.

Cast crop values to integers to prevent PHP error caused by implicit conversion from float to int values when cropping images using ImageMagick.

Props skithund, mai21, nicomollet, amanias1977, joedolson.
Fixes #59782.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/image-edit.php

    r58456 r58457  
    737737
    738738                    $scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( $w, $h ); // Discard preview scaling.
    739                     $image->crop( $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale );
     739                    $image->crop( );
    740740                } else {
    741741                    $scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( imagesx( $image ), imagesy( $image ) ); // Discard preview scaling.
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r58447 r58457  
    622622                    $size = $image_editor->get_size();
    623623
    624                     $crop_x = round( ( $size['width'] * $args['left'] ) / 100.0 );
    625                     $crop_y = round( ( $size['height'] * $args['top'] ) / 100.0 );
    626                     $width  = round( ( $size['width'] * $args['width'] ) / 100.0 );
    627                     $height = round( ( $size['height'] * $args['height'] ) / 100.0 );
     624                    $crop_x = round( ( $size['width'] * $args['left'] ) / 100.0 );
     625                    $crop_y = round( ( $size['height'] * $args['top'] ) / 100.0 );
     626                    $width  = round( ( $size['width'] * $args['width'] ) / 100.0 );
     627                    $height = round( ( $size['height'] * $args['height'] ) / 100.0 );
    628628
    629629                    if ( $size['width'] !== $width && $size['height'] !== $height ) {
  • trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php

    r58447 r58457  
    23772377        $this->assertCount( 1, WP_Image_Editor_Mock::$spy['crop'] );
    23782378        $this->assertSame(
    2379             array( 320.0, 48.0, 64.0, 24.0 ),
     2379            array( 320 ),
    23802380            WP_Image_Editor_Mock::$spy['crop'][0]
    23812381        );
Note: See TracChangeset for help on using the changeset viewer.