Hey all,
I'm writing a function that will resize an image on the fly when it is called and an image name is passed to it. It works perfectly if the image is in the same directory as the code, but as soon as the image is put in a different directory, I can't get it to work. Here's the resizeimage.php code:
<?
if (!$max_width)
$max_width = 150;
if (!$max_height)
$max_height = 100;
$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if (($width <= $max_width) && ($height <= $max_height)) {
$tn_width = $width;
$tn_height = $height;
} elseif (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
} else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$src = ImageCreateFromJpeg($image);
$dst = imagecreatetruecolor($tn_width, $tn_height);
imagecopyresampled($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
ImageJpeg($dst);
ImageDestroy($src);
ImageDestroy($dst);
?>
And here's how I'm calling it. I'm calling it through an <img> tag and I'm passing the image location which is "productimages/".
$imPath = "productimages/$productRow[jpglocation]";
print "<img src=\"resizefunction.php?image=$imPath\">";
Any help on this would be awesome! Thanks a lot.
insectis