kamkam
08-29-2009, 11:15 AM
Hi;
How i can insert an resized image into a html file, please.
If i do like the following, it does not work. Could any one help, please.
<?php
function resizeImage($originalImage,$toWidth,$toHeight, $maintain=true){
//check that image exists
if (!is_file($originalImage) || !is_readable($originalImage)) return false;
// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
if ($maintain) list($newWidth, $newHeight) = ( (($toWidth/$toHeight) > ($width/$height)) ?array (intval(($toWidth * $width/$height)), intval($toHeight)) : array (intval($toWidth), intval(($toHeight * $height/$width))));
// Resize the original image
$imageResized = imagecreatetruecolor($newWidth, $newHeight);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
return $imageResized;
}
?>
<html>
<body>
I want the image sit under me.
<?php
$image=resizeImage("testme.jpg",200,200,"true"); //this one shows on the browser
imagejpeg($image, null, 20);
?>
</body>
</html>
How i can insert an resized image into a html file, please.
If i do like the following, it does not work. Could any one help, please.
<?php
function resizeImage($originalImage,$toWidth,$toHeight, $maintain=true){
//check that image exists
if (!is_file($originalImage) || !is_readable($originalImage)) return false;
// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
if ($maintain) list($newWidth, $newHeight) = ( (($toWidth/$toHeight) > ($width/$height)) ?array (intval(($toWidth * $width/$height)), intval($toHeight)) : array (intval($toWidth), intval(($toHeight * $height/$width))));
// Resize the original image
$imageResized = imagecreatetruecolor($newWidth, $newHeight);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
return $imageResized;
}
?>
<html>
<body>
I want the image sit under me.
<?php
$image=resizeImage("testme.jpg",200,200,"true"); //this one shows on the browser
imagejpeg($image, null, 20);
?>
</body>
</html>