|
|
|
Resize an Image
12
You can use this function to dynamically generate html "width/height" for use with displaying a thumbnail image usingthe original image. This will help save in making dup images just for display as a thumbnail.
It takes two arguments, the path to where the image is stored and the desired width or height.
Please comment or improve this code
.
It takes two arguments, the path to where the image is stored and the desired width or height.
Please comment or improve this code
. /** resize_image()
*
* This functions resizes an image to any size
* specified.
*
* @ARGUMENTS: 2
* - $image: This is the path to the image to be resized
* - $target: This is the target widht/height
* @RETURNS:
* - html width/height string for an image tag
**/
function resize_image($image,$target)
{
// Get the current image size
$image = getimagesize($image);
// Get the percentage to resize the image
if ($image[0] > $image[1])
{
$percent = $target / $image[0];
}
else
{
$percent = $target / $image[1];
}
// Get the new width and height
$w = round($image[0] * $percent);
$h = round($image[1] * $percent);
// Return as an html widht/height attribute
$htmlWH = "width=\"" . $w . "\" height=\"" . $h . "\"";
return $htmlWH;
}




If thats too confusing search GD Library on Google.