From c428ba7cbae5bb735b5cfe9a857ee016d52bb48b Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Mon, 28 Apr 2025 15:39:24 +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]. Props sirlouen, adamsilverstein, audrasjb, pbiron, sainathpoojary, dilipbheda, pratiklondhe. Fixes #63302. See #61167. Built from https://develop.svn.wordpress.org/trunk@60195 git-svn-id: http://core.svn.wordpress.org/trunk@59531 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 d0b8f079c8..ffa17cb3d0 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.9-alpha-60193'; +$wp_version = '6.9-alpha-60195'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.