Given that you want to make a thumbnail and save it, you can implement a convenient resize function, for example:
<?php function resize($sourcefile, $endfile, $thumbwidth, $thumbheight, $quality){ $ext1 = explode(".",trim($sourcefile)); $ext = strtolower(trim(array_slice($sext1,-1))); switch($ext): case 'jpg' or 'jpeg': $img = imagecreatefromjpeg($sourcefile); break; case 'gif': $img = imagecreatefromgif($sourcefile); break; case 'png': $img = imagecreatefrompng($sourcefile); break; endswitch; $width = imagesx( $img ); $height = imagesy( $img ); if ($width > $height) { $newwidth = $thumbwidth; $divisor = $width / $thumbwidth; $newheight = floor( $height / $divisor); } else { $newheight = $thumbheight; $divisor = $height / $thumbheight; $newwidth = floor( $width / $divisor ); } // Create a new temporary image. $tmpimg = imagecreatetruecolor( $newwidth, $newheight ); // Copy and resize old image into new image. imagecopyresampled( $tmpimg, $img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height ); // Save thumbnail into a file. switch($ext): case 'jpg' or 'jpeg': $makeimg = imagejpeg($tmpimg, $endfile, $quality); break; case 'gif': $makeimg = imagegif($tmpimg, $endfile, $quality); break; case 'png': $makeimg = imagepng($tmpimg, $endfile, $quality); break; endswitch; // release the memory imagedestroy($tmpimg); imagedestroy($img); if($makeimg){ chmod($endfile,0755); return true; }else{ return false; } } ?>
Then, after you copied the file to your server using one of my methods in my answer above this, you can simply apply the function as follows:
$doresize = resize($sourcefile, $endfile, $thumbwidth, $thumbheight, $quality); echo ($doresize == true ? "IT WORKED" : "IT FAILED");
This feature serves me pretty well. I apply it to 1000 images a day and it works like a charm.