Does anyone know the code to resize an image that has been uploaded? I have the following code to upload the image: <?php //create the directory if doesn't exists (should have write permissons) if(!is_dir("./files")) mkdir("./files", 0755); //move the uploaded file move_uploaded_file($_FILES['Filedata']['tmp_name'], "./files/myImage.jpg"); ?> I now need to resize the image to say 360*290 //thnx
Here you go... http://www.tutorialized.com/view/tutorial/Creating-thumbnail-Resize-an-image-with-PHP/24351
Here is my function that I use to resize images: public function doResize($szSource, $szDestination, $szExtension, $iResizeWidth, $iResizeHeight) { $szExtension = strtolower($szExtension); switch($szExtension) { case('jpg'): $pSource = @imagecreatefromjpeg($szSource); break; case('jpeg'): $pSource = @imagecreatefromjpeg($szSource); break; case('gif'): $pSource = @imagecreatefromgif($szSource); break; case('wbmp'): $pSource = @imagecreatefromwbmp($szSource); break; case('png'): $pSource = @imagecreatefrompng($szSource); break; } $pResized = @imagecreatetruecolor($iResizeWidth, $iResizeHeight); list($iWidth, $iHeight) = getimagesize($szSource); if(!@imagecopyresampled($pResized, $pSource, 0, 0, 0, 0, $iResizeWidth, $iResizeHeight, $iWidth, $iHeight)) { return false; } switch($szExtension) { case('jpg'): $pResult = imagejpeg($pResized, $szDestination, 100); break; case('jpeg'): $pResult = imagejpeg($pResized, $szDestination, 100); break; case('gif'): $pResult = imagegif($pResized, $szDestination); break; case('wbmp'): $pResult = imagewbmp($pResized, $szDestination); break; case('png'): $pResult = imagepng($pResized, $szDestination); break; } if($pResult) { return true; } return false; } PHP:
Thanks! Just to point out though, that function is from inside one of my classes, so if use the modular approach to PHP then simply remove public from the beginning of the function deceleration.