Hi everyone.
Hopefully this will be the last thing that I need to do to my shopping cart.
Basically I have a product details and it gives me the actual picture in its actual size.
In order to look more neat, I want to make the pictures to be like thumbnails ie all the pictures to be the same size (let's say 270x220) but when you click on it the image to be shown in the actual size (actually the PerttyPhoto already does that) .
Right now, when you click on the image, the PrettyPhoto script makes it very nice and I want it to stay that way.
I found a code which should make thumbnails:
function createThumbnail($filename) {
require 'config.php';
if(preg_match('/[.](jpg)$/', $filename)) {
$im = imagecreatefromjpeg($path_to_image_directory . $filename);
} else if (preg_match('/[.](gif)$/', $filename)) {
$im = imagecreatefromgif($path_to_image_directory . $filename);
} else if (preg_match('/[.](png)$/', $filename)) {
$im = imagecreatefrompng($path_to_image_directory . $filename);
}
$ox = imagesx($im);
$oy = imagesy($im);
$nx = $final_width_of_image;
$ny = floor($oy * ($final_width_of_image / $ox));
$nm = imagecreatetruecolor($nx, $ny);
imagecopyresized($nm, $im, 0,0,0,0,$nx,$ny,$ox,$oy);
if(!file_exists($path_to_thumbs_directory)) {
if(!mkdir($path_to_thumbs_directory)) {
die("There was a problem. Please try again!");
}
}
imagejpeg($nm, $path_to_thumbs_directory . $filename);
$tn = '<img src="' . $path_to_thumbs_directory . $filename . '" alt="image" />';
$tn .= '<br />Congratulations. Your file has been successfully uploaded, and a thumbnail has been created.';
echo $tn;
}
and the code that need to be in the index:
<?php
require 'config.php';
require 'functions.php';
if(isset($_FILES['fupload'])) {
if(preg_match('/[.](jpg)|(gif)|(png)$/', $_FILES['fupload']['name'])) {
$filename = $_FILES['fupload']['name'];
$source = $_FILES['fupload']['tmp_name'];
$target = $path_to_image_directory . $filename;
move_uploaded_file($source, $target);
createThumbnail($filename);
}
}
?>
But the thing is, since I take my pictures from the database I don't know how to make this code work for me.
My code is this:
<td cless="productWrap">
<td class="productItem">
<a class="productImage" href="<?php echo $pd_image; ?>" rel="prettyPhoto" title="<?php echo $pd_name;?>">
<img src="<?php echo $pd_image; ?>" alt="<?php echo $pd_name; ?>">
</a>
</td>
</td>
Please help.