0

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:

Error screenshot

Here are my GD details:

my GD version.

<?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);
}
?>
halfer
  • 19,824
  • 17
  • 99
  • 186
sopanha
  • 345
  • 3
  • 11
  • 2
    Most possibly there is other output prefixing your image - whitespace or PHP warnings. Open the defective image in a text or hex editor and take a look. – Eugen Rieck May 01 '14 at 14:58
  • 1
    You are getting an error in your PHP code, and that error is trying to be rendered as an image. Remove the `header` line for now, and see what gets printed to the page. – gen_Eric May 01 '14 at 15:02
  • @Eugen Rieck, thank so much. it was defective image. i don't know why print screen images are defected. i tried on image from google, it's working fine. you saved my day. – sopanha May 01 '14 at 15:07

1 Answers1

-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/