From 9360266c51e501b2e08b57f550b2db7af6c35c6b Mon Sep 17 00:00:00 2001 From: joedolson Date: Fri, 21 Jun 2024 20:37:11 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@58457 git-svn-id: http://core.svn.wordpress.org/trunk@57906 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/image-edit.php | 2 +- .../endpoints/class-wp-rest-attachments-controller.php | 8 ++++---- wp-includes/version.php | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php index 9508a9a22b..eea6099c9b 100644 --- a/wp-admin/includes/image-edit.php +++ b/wp-admin/includes/image-edit.php @@ -736,7 +736,7 @@ function image_edit_apply_changes( $image, $changes ) { $h = $size['height']; $scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( $w, $h ); // Discard preview scaling. - $image->crop( $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale ); + $image->crop( (int) ( $sel->x * $scale ), (int) ( $sel->y * $scale ), (int) ( $sel->w * $scale ), (int) ( $sel->h * $scale ) ); } else { $scale = isset( $sel->r ) ? $sel->r : 1 / _image_get_preview_ratio( imagesx( $image ), imagesy( $image ) ); // Discard preview scaling. $image = _crop_image_resource( $image, $sel->x * $scale, $sel->y * $scale, $sel->w * $scale, $sel->h * $scale ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index dbab4c933e..370025d927 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php @@ -621,10 +621,10 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { case 'crop': $size = $image_editor->get_size(); - $crop_x = round( ( $size['width'] * $args['left'] ) / 100.0 ); - $crop_y = round( ( $size['height'] * $args['top'] ) / 100.0 ); - $width = round( ( $size['width'] * $args['width'] ) / 100.0 ); - $height = round( ( $size['height'] * $args['height'] ) / 100.0 ); + $crop_x = (int) round( ( $size['width'] * $args['left'] ) / 100.0 ); + $crop_y = (int) round( ( $size['height'] * $args['top'] ) / 100.0 ); + $width = (int) round( ( $size['width'] * $args['width'] ) / 100.0 ); + $height = (int) round( ( $size['height'] * $args['height'] ) / 100.0 ); if ( $size['width'] !== $width && $size['height'] !== $height ) { $result = $image_editor->crop( $crop_x, $crop_y, $width, $height ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 2fed24b66c..95158f8fd7 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.6-beta3-58456'; +$wp_version = '6.6-beta3-58457'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.