GD Library and outputing image

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Never really used the GD much before very straightforward but how do I 
output the image on a page. This is  fine on a php page on its own but what 
about one where the headers are already sent?


I take it I can do something like  this <img 
scr="get_image.php?url=$img_url"></a>. Anyone got a better method?




$image = imagecreatefromjpeg($img_url);
if ($image === false) { die ('Unable to open image'); }

// Get original width and height
echo $width = imagesx($image);
echo $height = imagesy($image);

// New width and height
$new_width = 200;
$new_height = 150;

// Resample
$image_resized = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, 
$new_height, $width, $height);

// Display resized image
header('Content-type: image/jpeg');
imagejpeg($image_resized);
die();

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux