• Hi.

    I can’n be sure that I’m in the right section of this forum. Actually I’m am here because I’m not sure about what’s happening… rs

    Well, I use the “Post thumbnail Editor” in my website. After move my site to a IIS Server (I know, it sux, but my customer call for it), the page for select area for the thumbnail did not show the main image anymore.

    After debug many .php files, I found that the source of this bug was a WordPress core instruction. In the wp-admin/includes/image-edit.php you can found these lines (beginning at line 239):

    function wp_stream_image($image, $mime_type, $post_id) {
    	$image = apply_filters('image_save_pre', $image, $post_id);
    
    	switch ( $mime_type ) {
    		case 'image/jpeg':
    			header('Content-Type: image/jpeg');
    			return imagejpeg($image, null, 90);
    		case 'image/png':
    			header('Content-Type: image/png');
    			return imagepng($image);
    		case 'image/gif':
    			header('Content-Type: image/gif');
    			return imagegif($image);
    		default:
    			return false;
    	}
    }

    In my tests, I have used jpeg images and, I can’t say why, the header had no effect and the image was blank.

    Searching for a solution, a have found this forum page and a instruction call my attention. And it solved the bug!

    function wp_stream_image($image, $mime_type, $post_id) {
    	$image = apply_filters('image_save_pre', $image, $post_id);
    
    	while (@ob_end_clean());
    
    	switch ( $mime_type ) {
    		case 'image/jpeg':
    			header('Content-Type: image/jpeg');
    			return imagejpeg($image, null, 90);
    		case 'image/png':
    			header('Content-Type: image/png');
    			return imagepng($image);
    		case 'image/gif':
    			header('Content-Type: image/gif');
    			return imagegif($image);
    		default:
    			return false;
    	}
    }

    I found that this ob_end_clean function “discards the contents of the topmost output buffer and turns off this output buffering”. Ok, it works for me, but what I want to know is if is safe to call this function there. As I said, I’m at WordPress Core. Does anyone know a better solution?

    Many thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • I solved the same issue/behavior. It was caused by a theme with a functions.php with some empty lines at the end of the file after the ?>. (Solution: remove the empty lines). If this isn’t the case I imagine a similar issue could be caused by a plugin…

    Hi,

    I just spend some time figuring out why this did not work on multiple site we have.
    We found 2 possible cause:
    1 – Any spaces left before the first <?php tag or after the last ?> tag. this could be in any plugins or in the current themes files.

    2- I also found that if you have anything using the hook image_save_pre it will cause this feature to fail.

    Hope this helps anyone.

    Have fun

    @stakabo – Thanks!!

    Thanks, can u explain what means ” if you have anything using the hook image_save_pre it will cause this feature to fail.”

    Sorry i don’t understand… :-\

    There is a WP hook called “image_save_pre”.

    This hooked is expecting your function to send back an image.
    If it does not retunr an image, it will make wp_stream_image() fail to do it’s job.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘admin-ajax.php imgedit-preview header problem’ is closed to new replies.