问题
I'm using GD library to resize image. Why is not header('Content-Type: image/jpeg');
working?
It gave me an error as you can see in pic below:

Here are my GD details:

<?php
header("Content-type: image/jpeg");
if(isset($_GET['image'])){
$image = $_GET['image'];
list($image_width, $image_height)= getimagesize($image);
$new_size = ($image_width+$image_height)/($image_width*($image_height/45));
$new_width = $image_width * $new_size;
$new_height = $image_height * $new_size;
$new_image = imagecreatetruecolor($new_width, $new_height);
$old_image = imagecreatefromjpeg($image);
imagecopyresized($new_image, $old_image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
imagejpeg($new_image);
}
?>
回答1:
It would always better to use the existing scripts/libraries instead of reinventing the wheel... try using timthumb or similar... that would save a lot of time and error free...
http://www.phpguy.in/simple-way-to-generate-thumbnails-in-php/
来源:https://stackoverflow.com/questions/23410195/why-is-content-type-image-jpeg-header-not-working