[wp-trac] [WordPress Trac] #62729: stream_preview_image() should stream with right mime type, if filter _load_image_to_edit_path change file with different mime type

WordPress Trac noreply at wordpress.org
Thu Feb 13 14:30:17 UTC 2025


#62729: stream_preview_image() should stream with right mime type, if filter
_load_image_to_edit_path change file with different mime type
--------------------------------------+------------------------------
 Reporter:  Hrohh                     |       Owner:  pbearne
     Type:  defect (bug)              |      Status:  assigned
 Priority:  normal                    |   Milestone:  Awaiting Review
Component:  Post Thumbnails           |     Version:  6.7.1
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+------------------------------

Comment (by Hrohh):

 Hi sir, sorry for long delay.

 function wp_save_image is here =>
 https://github.com/WordPress/wordpress-
 develop/blob/626d9af280566d008ccf501952f119fb0ce61662/src/wp-
 admin/includes/image-edit.php#L904

 relevant code is

 {{{#!php
 <?php
    $post    = get_post( $post_id );
    $img     = wp_get_image_editor( _load_image_to_edit_path( $post_id,
 'full' ) );
    $saved_image = wp_save_image_file( $new_path, $img,
 $post->post_mime_type, $post_id );
 }}}

 so with your patch is should be

 {{{#!php
 <?php
    $post      = get_post( $post_id );
    $img       = wp_get_image_editor( _load_image_to_edit_path( $post_id,
 'full' ) );
    $mime_type = $post->post_mime_type;
    if ( method_exists( $img, 'get_mime_type' ) ) {
        $mime_type = $img->get_mime_type();
    }

    $saved_image = wp_save_image_file( $new_path, $img, $mime_type,
 $post_id );
 }}}

 Thank you.

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


More information about the wp-trac mailing list