Image manipulation with PHP & the GD library, Part 2
(Page 4 out of 3)
« Previous: Watermarking Images & Conclusion
This article was posted on Monday, August 14th, 2006 at 4:44 pm. You can follow any responses to this article through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
August 19th, 2006 at 12:55 pm
Hi
i want to resample an image to half its original size but there are not properly done
using the following code so please help me for solving the code :
0) {
$row = mysql_fetch_array ($result);
$percent = 0.5; //ex
$image_type = $row[”image_type”];
$image = $row[”image”];
$image_name = $row[”image_name”];
header(’Content-type: $image_type’);
// Get new dimensions
$width = imagesx($image);
$height = imagesx($image);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_p = imagecreatetruecolor($new_width,$new_height);
$imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
header(’Content-type: image/jpeg’);
imagejpeg($image_p);
Regards ,
vish
}
?>
August 23rd, 2006 at 9:51 am
Hi vish,
while watching your code I found header(’Content-type: $image_type’); and header(’Content-type: image/jpeg’);.
You can only send one header at once, not two. Just use the last one to make sure everything gets done before you put the resized image on screen.
Then, if you need to resize gif and png you need another header, so implement a switch case i.e. to get the type and use the right functions for these types.
best regards,
Harald Doderer
Director Emedian Ltd.
www.emedian.net
August 24th, 2006 at 11:42 am
short and useful tutorial
August 28th, 2006 at 9:41 am
Thank you so much for this tutorial. This is exactly what I was looking for :) Thank you!
August 29th, 2006 at 4:58 pm
it help me to solve my problem so thanyou very much.