From a46e5b9c098a745544818978a5acb694cac9c1b2 Mon Sep 17 00:00:00 2001 From: desrosj Date: Mon, 28 Apr 2025 15:57:27 +0000 Subject: [PATCH] Media: Don't try to resize image formats which can't be resized While having a mime type with an "image" prefix, SVG images are in fact "Scalable Vector Graphics" that can be scaled directly. Follow-up to [60084]. Reviewed by desrosj. Backports [60195] to the 6.8 branch. Props sirlouen, adamsilverstein, audrasjb, pbiron, sainathpoojary, dilipbheda, pratiklondhe. Fixes #63302. See #61167. Built from https://develop.svn.wordpress.org/branches/6.8@60196 git-svn-id: http://core.svn.wordpress.org/branches/6.8@59532 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../class-wp-rest-attachments-controller.php | 12 ++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) 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 4c49a1f335..589e0e2cce 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 @@ -155,8 +155,16 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { isset( $files['file']['type'] ) && str_starts_with( $files['file']['type'], 'image/' ) ) { - // Check if the image editor supports the type. - if ( ! wp_image_editor_supports( array( 'mime_type' => $files['file']['type'] ) ) ) { + // List of non-resizable image formats. + $editor_non_resizable_formats = array( + 'image/svg+xml', + ); + + // Check if the image editor supports the type or ignore if it isn't a format resizable by an editor. + if ( + ! in_array( $files['file']['type'], $editor_non_resizable_formats, true ) && + ! wp_image_editor_supports( array( 'mime_type' => $files['file']['type'] ) ) + ) { return new WP_Error( 'rest_upload_image_type_not_supported', __( 'The web server cannot generate responsive image sizes for this image. Convert it to JPEG or PNG before uploading.' ), diff --git a/wp-includes/version.php b/wp-includes/version.php index 23be6acbb8..e886ed84b8 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8.1-alpha-60194'; +$wp_version = '6.8.1-alpha-60196'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.