Why is Content-Type: image/jpeg header not working? [duplicate]

£可爱£侵袭症+ 提交于 2019-12-13 05:02:52

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!