Hi
I'm trying to resize images and then display them on screen. However, my code isn't working, the image won't display on screen. The image I am passing to the function is stored in the same folder as the script. I don't understand why it won't work. Can someone help please.
thank you.
function ResizeImage($originalImage, $toWidth, $toHeight)
{
echo $originalImage . " " , $toWidth . " " . $toHeight;
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;
}
$newImage = ResizeImage("DSC_0005.jpg", '150', '100');
echo "<img src=\"$newImage\">";