Title: admin-ajax.php imgedit-preview header problem
Last modified: August 20, 2016

---

# admin-ajax.php imgedit-preview header problem

 *  [hugofcampos](https://wordpress.org/support/users/hugofcampos/)
 * (@hugofcampos)
 * [14 years ago](https://wordpress.org/support/topic/admin-ajaxphp-imgedit-preview-header-problem/)
 * 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](http://wordpress.org/extend/plugins/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](http://bytes.com/topic/php/answers/463466-imagejpeg-generating-string-not-image-even-header-content-type-image-jpeg)
   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](http://br.php.net/manual/en/function.ob-end-clean.php)“
   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)

 *  [sewpafly](https://wordpress.org/support/users/sewpafly/)
 * (@sewpafly)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/admin-ajaxphp-imgedit-preview-header-problem/#post-2645589)
 * 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…
 *  [stakabo](https://wordpress.org/support/users/stakabo/)
 * (@stakabo)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/admin-ajaxphp-imgedit-preview-header-problem/#post-2645623)
 * 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
 *  [sewpafly](https://wordpress.org/support/users/sewpafly/)
 * (@sewpafly)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/admin-ajaxphp-imgedit-preview-header-problem/#post-2645624)
 * [@stakabo](https://wordpress.org/support/users/stakabo/) – Thanks!!
 *  [Mediacleg](https://wordpress.org/support/users/mediacleg/)
 * (@mediacleg)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/admin-ajaxphp-imgedit-preview-header-problem/#post-2645625)
 * 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… :-\
 *  [stakabo](https://wordpress.org/support/users/stakabo/)
 * (@stakabo)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/admin-ajaxphp-imgedit-preview-header-problem/#post-2645632)
 * 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.

## Tags

 * [admin](https://wordpress.org/support/topic-tag/admin/)
 * [header](https://wordpress.org/support/topic-tag/header/)
 * [media](https://wordpress.org/support/topic-tag/media/)
 * [ob_end_clean](https://wordpress.org/support/topic-tag/ob_end_clean/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 4 participants
 * Last reply from: [stakabo](https://wordpress.org/support/users/stakabo/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/admin-ajaxphp-imgedit-preview-header-problem/#post-2645632)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
