[wp-trac] [WordPress Trac] #63302: SVG images can't be uploaded anymore due to a resizing issue

WordPress Trac noreply at wordpress.org
Fri Apr 18 16:27:45 UTC 2025


#63302: SVG images can't be uploaded anymore due to a resizing issue
-----------------------------------------------+---------------------
 Reporter:  audrasjb                           |       Owner:  (none)
     Type:  defect (bug)                       |      Status:  new
 Priority:  normal                             |   Milestone:  6.8.1
Component:  Editor                             |     Version:  6.8
 Severity:  normal                             |  Resolution:
 Keywords:  has-screenshots changes-requested  |     Focuses:
-----------------------------------------------+---------------------

Comment (by pbiron):

 Replying to [comment:7 sainathpoojary]:
 > 2. Block Editor path (wp-includes/rest-api/endpoints/class-wp-rest-
 attachments-controller.php):
 >
 > {{{
 > if (
 >     $prevent_unsupported_uploads &&
 >     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'] ) ) ) {
 >         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.' ),
 >             array( 'status' => 400 )
 >         );
 >     }
 > }
 > }}}

 Yup, this looks to be the cause.  `wp_image_editor_supports()` eventually
 calls `WP_Image_Editor_GD::supports_mime_type()` or
 `WP_Image_Editor_Imagick::supports_mime_type()`, both of which return
 `false` for 'image/svg+xml'.

 The problem is that SVG images don't need to have "responsive images
 generated"...so I'm not sure that calling `wp_image_editor_supports()`
 here is the right thing to do.

 Perhaps we could introduce something like a
 `wp_image_editor_needs_to_support()` function (function name not great,
 suggertions welcome :-)) that applies a filter which tools like `Safe SVG`
 could hook into and return false, and then the change in
 `WP_REST_Attachments_Controller::create_item_permissions_check()` in 6.8
 could be changed to something like:

 {{{#!php
 if (
     $prevent_unsupported_uploads &&
     isset( $files['file']['type'] ) &&
     str_starts_with( $files['file']['type'], 'image/' )
 ) {
     // Check if the image editor supports the type.
     if (
         wp_image_editor_needs_to_support( array( 'mime_type' =>
 $files['file']['type'] ) ) &&
         ! 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.' ),
             array( 'status' => 400 )
         );
     }
 }
 }}}

 thoughts?

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63302#comment:16>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list