Great, works a treat.. especially with my previously written code... (had to use my own version)
*Note* Revised version is below
function resizeImage($file,$scale="",$width="",$height="") { //Make sure that the vars (scale, width, height) are all numeric if((is_numeric($scale) === TRUE) || (is_numeric($width) === TRUE && is_numeric($height) === TRUE){
// If they wish to scale the image. // You gotta make sure that it is set AND that it has a value. if(isset($scale) && $scale != "") { // Create our image object from the image. $fullImage = imagecreatefromjpeg($file); // Get the image size, used in calculations later. $fullSize = getimagesize($file); // If there is NOT a thumbnail for this image, make one. if(!file_exists("tn_".$file)) { // Create our thumbnail size, so we can resize to this, and save it. $tnImage = imagecreatetruecolor($fullSize[0]/$scale, $fullSize[1]/$scale); // Resize the image.
imagecopyresampled($tnImage,$fullImage,0,0,0,0,$fullSize[0]/$scale,$fullSize[1]/$scale,$fullSize[0],$fullSize[1]); // Create a new image thumbnail.
imagejpeg($tnImage, "tn_".$file);
// Clean Up.
imagedestroy($fullImage);
imagedestroy($tnImage); // Return our new image. return"tn_".$file; } // If there is a thumbnail file, lets just load it. else return"tn_".$file; } // If they want to force whatever size they want. elseif(isset($width) && isset($height)) { return"tn_".$file; } else { returnfalse; } }else{ //Throw error: return"Problem with the damned variables!"; } }
*Note* Revised version is below
function resizeImage($file,$scale="",$width="",$height="")
{
//Make sure that the vars (scale, width, height) are all numeric
if((is_numeric($scale) === TRUE) ||
(is_numeric($width) === TRUE && is_numeric($height) === TRUE){
// If they wish to scale the image.
// You gotta make sure that it is set AND that it has a value.
if (isset($scale) && $scale != "")
{
// Create our image object from the image.
$fullImage = imagecreatefromjpeg($file);
// Get the image size, used in calculations later.
$fullSize = getimagesize($file);
// If there is NOT a thumbnail for this image, make one.
if (!file_exists("tn_".$file))
{
// Create our thumbnail size, so we can resize to this, and save it.
$tnImage = imagecreatetruecolor($fullSize[0]/$scale, $fullSize[1]/$scale);
// Resize the image.
imagecopyresampled($tnImage,$fullImage,0,0,0,0,$fullSize[0]/$scale,$fullSize[1]/$scale,$fullSize[0],$fullSize[1]);
// Create a new image thumbnail.
imagejpeg($tnImage, "tn_".$file);
// Clean Up.
imagedestroy($fullImage);
imagedestroy($tnImage);
// Return our new image.
return "tn_".$file;
}
// If there is a thumbnail file, lets just load it.
else
return "tn_".$file;
}
// If they want to force whatever size they want.
elseif (isset($width) && isset($height))
{
return "tn_".$file;
}
else
{
return false;
}
}else{
//Throw error:
return "Problem with the damned variables!";
}
}