Ok so I have a function to resize images when I upload, its called twice once for the thumbnail once for a full size. I’ve used my uploading a number of times so far and its always worked perfectly but now I’m having a problem. When I upload a square image, it works for the thumbnail but not the full size. Anyway here’s what I got, maybe I missed something…
function imageResize($src,$target,$newWidth,$newHeight) {
// $src = original file
// $target = new file
// $newWidth / $newHeight represent maximum dimensions
list($origWidth,$origHeight) = getimagesize($src); // Get original dimensions
if( $origWidth > $origHeight ) { // set new width/height to maintain aspect ratio
$newHeight = ($newWidth/$origWidth)*$origHeight;
} else {
$newWidth = ($newHeight/$origHeight)*$origWidth;
}
if( $origHeight < $newHeight && $origWidth < $newWidth) {
$newHeight = $origHeight;
$newWidth = $origWidth;
}
$base = imagecreatefromjpeg($src); // open source
$temp = imagecreatetruecolor($newWidth,$newHeight); //create new file
imagecopyresampled($temp,$base,0,0,0,0,$newWidth,$newHeight,$origWidth,$origHeight); // resample source into new file
if ( imagejpeg($temp,$target) ) { // copy new file to target location, if successful return true otherwise return false.
return TRUE;
} else {
return FALSE;
}
}
// upload script calling it
$tnfile = "{$uploaddir}{$filename}.{$ext}";
$viewfile = "{$uploaddir}{$filename}_1.{$ext}";
$error = 0;
if( imageResize($pics,$tnfile,"200","133") ) {
$content .= "Thumbnail successful.<br />";
} else {
$content .= "Thumbnail failed.<br />";
$error++;
}
if( imageResize($pics,$viewfile,"640","800") ) {
$content .= "View file successful.<br />";
} else {
$content .= "View file failed.<br />";
$error++;
}
Like I said it worked on the thumbnail, so I’m lost i thought maybe because it was square but then why would it still work for the thumbnail? Also there is quite a bit more to upload part, if you feel I should post that too let me know.
As always, thanks in advance! <3