Hi Guys,
I found this code that generates thumbnails from the images and displays them, unfortunately it creates new images, can somebody please modify it to generateto display the thumbnails without generating new images?
# Prepends the prefix to the filename of $imageFile, and finds the relative position of $imageFile
# in our image output folder.
# Example: "c:\digicam\yosemite\t.jpg", "tn_" -> "c:\web\travel\images\yosemite\tn_t.jpg"
#
function getNewFilename($imageFile, $prefix)
{
$filename = basename($imageFile);
$dirname = dirname($imageFile);
$dirname = str_replace("digicam/", "web/travel/", $dirname);
$filename = $prefix . $filename;
return $dirname . "/" . $filename;
}
# Resizes the passed $imageFile filename so that the longest side in either dimension is $maxDimension pixels.
# This function returns the filename of the resized image, prepended with the passed filename $prefix.
function resizeImage($imageFile, $maxDimension, $prefix)
{
list($width, $height, $type, $attr) = getimagesize($imageFile);
# Find the new height and width
$newWidth = $width;
$newHeight = $height;
if ($newWidth > $maxDimension)
{
$newHeight = $height * ($maxDimension / $width);
$newWidth = $maxDimension;
}
if ($newHeight > $maxDimension)
{
$newWidth = $newWidth * ($maxDimension / $newHeight);
$newHeight = $maxDimension;
}
# Get the new image filename
$newFile = getNewFilename($imageFile, $prefix);
# Resize the image (if it hasn't been done already)
if (!file_exists($newFile))
{
$image_p = imagecreatetruecolor($newWidth, $newHeight);
$image = imagecreatefromjpeg($imageFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
if (!file_exists(dirname($newFile))) mkdirs(dirname($newFile));
imagejpeg($image_p, $newFile, 60);
}
return $newFile;
}
Cheers