Make WordPress Core


Ignore:
Timestamp:
04/28/2025 03:37:27 PM (3 months ago)
Author:
jorbin
Message:

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.

File:
1 edited

Legend:

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

    r60084 r60195  
    156156            str_starts_with( $files['file']['type'], 'image/' )
    157157        ) {
    158             // Check if the image editor supports the type.
    159             if ( ! wp_image_editor_supports( array( 'mime_type' => $files['file']['type'] ) ) ) {
     158            // List of non-resizable image formats.
     159            $editor_non_resizable_formats = array(
     160                'image/svg+xml',
     161            );
     162
     163            // Check if the image editor supports the type or ignore if it isn't a format resizable by an editor.
     164            if (
     165                ! in_array( $files['file']['type'], $editor_non_resizable_formats, true ) &&
     166                ! wp_image_editor_supports( array( 'mime_type' => $files['file']['type'] ) )
     167            ) {
    160168                return new WP_Error(
    161169                    'rest_upload_image_type_not_supported',
Note: See TracChangeset for help on using the changeset viewer.