Opened 7 weeks ago
Last modified 2 weeks ago
#62729 assigned defect (bug)
stream_preview_image() should stream with right mime type, if filter _load_image_to_edit_path change file with different mime type
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.7.1 |
Component: | Post Thumbnails | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
Hi, im working on allowing image editor for PDF thumnbails https://core.trac.wordpress.org/ticket/62712.
in functiion stream_preview_image() in wp-admin/includes/image-edit.php - line 766
is function with filter
<?php _load_image_to_edit_path( $post_id )
we can change filepath, but for example if we change to
metadata['sizes']['full']
which has mimetype image/jpg, function stream_preview_image() dont send image to browser. Bug is in
<?php return wp_stream_image( $img, $post->post_mime_type, $post_id );
should be
<?php return wp_stream_image( $img, $img['mime-type'], $attachment_id );
Change History (7)
This ticket was mentioned in PR #8041 on WordPress/wordpress-develop by @sukhendu2002.
7 weeks ago
#1
- Keywords has-patch added
This ticket was mentioned in PR #8117 on WordPress/wordpress-develop by @pbearne.
4 weeks ago
#2
- Keywords has-unit-tests added
Introduced detailed PHPUnit tests for AJAX image cropping preview functionality. Made get_mime_type
a public method and adjusted MIME type handling in stream_preview_image
for better compatibility with image editors. These changes ensure more robustness in image handling and testing.
Trac ticket: [](https://core.trac.wordpress.org/ticket/62729)
#3
@
4 weeks ago
- Owner set to pbearne
- Status changed from new to assigned
I have added some test but I was not able to test the header change in this ticket as the test suit does not seem to allow this
maybe someone else can help testing
Paul
#4
@
2 weeks ago
I have nasty fix
<?php // bug in wp_stream_image in image-edit.php, bad mime type add_filter( 'image_editor_save_pre', 'core_thumbnail_generator_image_editor_save_pre', 10, 2 ); function core_thumbnail_generator_image_editor_save_pre( $image, $attachment_id ) { if ( did_action( 'wp_ajax_imgedit-preview' ) ) { if ( is_wp_error( $image->stream() ) ) { wp_die( -1 ); } else { wp_die(); } } }
#5
follow-up:
↓ 6
@
2 weeks ago
Same bug is in
<?php function wp_save_image( $post_id ) { $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 );
Cannot change mime_type.
#6
in reply to:
↑ 5
@
2 weeks ago
Replying to Hrohh:
Same bug is in
<?php function wp_save_image( $post_id ) { $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 );Cannot change mime_type.
OK we will need to add a filter where in the function should put this?
Trac ticket: https://core.trac.wordpress.org/ticket/62729