kamkam
08-22-2009, 09:24 AM
Hi;
I am trying to output an image after imagecopyresampled, but it doesn't display any image on browser, could you tell me why, please.
it just out some thing like following:
����JFIF��
My original image is 36KB and 900*900
and i want them become to 18kb and 100&100
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">
</head>
<body>
<?php
function resizeImage($originalImage,$toWidth,$toHeight){
// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$xscale=$width/$toWidth;
$yscale=$height/$toHeight;
// Recalculate new size with default ratio
if ($yscale>$xscale){
$new_width = round($width * (1/$yscale));
$new_height = round($height * (1/$yscale));
}
else {
$new_width = round($width * (1/$xscale));
$new_height = round($height * (1/$xscale));
}
// Resize the original image
$imageResized = imagecreatetruecolor($new_width, $new_height);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
return $imageResized;
}
?>
<?php
$image= resizeImage("upload/testimage.jpg",200,200);
imagejpeg($image, null, 100);
//$info = getimagesize("upload/testimage.jpg");
//print_r($image);
?>
</body>
</html>
I am trying to output an image after imagecopyresampled, but it doesn't display any image on browser, could you tell me why, please.
it just out some thing like following:
����JFIF��
My original image is 36KB and 900*900
and i want them become to 18kb and 100&100
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">
</head>
<body>
<?php
function resizeImage($originalImage,$toWidth,$toHeight){
// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
$xscale=$width/$toWidth;
$yscale=$height/$toHeight;
// Recalculate new size with default ratio
if ($yscale>$xscale){
$new_width = round($width * (1/$yscale));
$new_height = round($height * (1/$yscale));
}
else {
$new_width = round($width * (1/$xscale));
$new_height = round($height * (1/$xscale));
}
// Resize the original image
$imageResized = imagecreatetruecolor($new_width, $new_height);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
return $imageResized;
}
?>
<?php
$image= resizeImage("upload/testimage.jpg",200,200);
imagejpeg($image, null, 100);
//$info = getimagesize("upload/testimage.jpg");
//print_r($image);
?>
</body>
</html>