I wrote a thumbnail function that basically did the following:
1. Check to see if the given image has a corresponding thumbnail
2. If so, skip to 4
3. If not, generate thumbnail
4. Display thumbnail
The thumbnails aren't being generated. Here's the function, it's driving me bonkers, I seriously can't see what's wrong with it, maybe you guys can... Feel free to use the function for urself if you want. It's commented so you guys can follow it.
Any ideas?
1. Check to see if the given image has a corresponding thumbnail
2. If so, skip to 4
3. If not, generate thumbnail
4. Display thumbnail
The thumbnails aren't being generated. Here's the function, it's driving me bonkers, I seriously can't see what's wrong with it, maybe you guys can... Feel free to use the function for urself if you want. It's commented so you guys can follow it.
Code:
function thumbit($filename){
if($filename){
if (file_exists($filename)) {
$condir = substr($filename, -(strlen(basename($filename))));
$origfilename = basename($filename);
if(!file_exists($condir.'tmb_'.$origfilename)){
#thumbnail doesn't exist, generate it, save it, and display it.
#Name you want to save your file as
$save = $condir.'tmb_'.$origfilename;
$file = $filename;
$size = 0.10;
header('Content-type: image/jpeg') ;
list($width, $height) = getimagesize($file) ;
$modwidth = 180; #$width * $size;
$modheight = 120; #$height * $size;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
#Here we are saving the .jpg, you can make this gif or png if you want
//the file name is set above, and the quality is set to 100%
imagejpeg($tn, $save, 100) ;
} else {
#thumbnail already exists, skip generation and display it
$image = imagecreatefromjpeg($condir.'tmb_'.$origfilename);
imagejpeg($image, null, 100);
}
} else {
echo "ThumbIt Function Error: The file $filename does not exist.";
}
} else {
echo "ThumbIt Function Error: Please provide an image to generate a thumbnail of.";
}
}

Comment