Hello friends, please am having problem with my image resize code the code is as below; $originalImage = $_FILES["file"]["name"]; $toWidth = 300; $toHeight = 300; function resizeImage($originalImage,$toWidth,$toHeight){ // Get the original geometry and calculate scales list($width, $height) = getimagesize($originalImage); $xscale=$width/$toWidth; $yscale=$height/$toHeight; // Recalculate new size with default ratio if ($yscale>$xscale){ $new_width = round($width * (1/$yscale)); $new_height = round($height * (1/$yscale)); } else { $new_width = round($width * (1/$xscale)); $new_height = round($height * (1/$xscale)); } // Resize the original image $imageResized = imagecreatetruecolor($new_width, $new_height); $imageTmp = imagecreatefromjpeg ($originalImage); imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $imageResized); $path2= "../upload/" . $imageResized; PHP: but the picture is not resized, and if i use $image = resizeImage() move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $image); $path2= "../upload/" . $image; PHP: no picture will be uploaded to my upload folder. please what can i do or which other lesser stress way can i resize my picture.
Try $image = resizeImage($originalImage,300,300); move_uploaded_file($_FILES["file"]["tmp_name"], "../upload/" . $image); $path2= "../upload/" . $image; Code (markup):
Hi, Solution for your site can be added by me and i'm available immediatley to you.My hourly rate is $8USD I have more than 5 Years of experience in web development. Feel free to contact me : Messenger ID: Gtalk:sanjeev786@gmail.com Yahoo: Skype: mrsanjeev.chauhan Looking forward to hear you. Thanks and Regards Subash
function resizeImage($originalImage,$toWidth,$toHeight){ // Get the original geometry and calculate scales list($width, $height) = getimagesize($originalImage); $xscale=$width/$toWidth; $yscale=$height/$toHeight; // Recalculate new size with default ratio if ($yscale>$xscale){ $new_width = round($width * (1/$yscale)); $new_height = round($height * (1/$yscale)); } else { $new_width = round($width * (1/$xscale)); $new_height = round($height * (1/$xscale)); } // Resize the original image $imageResized = imagecreatetruecolor($new_width, $new_height); $imageTmp = imagecreatefromjpeg ($originalImage); imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } $toWidth = 300; $toHeight = 300; $imageResized = resizeImage($_FILES['file']['tmp_name'],$toWidth,$toHeight); file_put_contents("../upload/{$_FILES['file']['name']}", $imageResized); PHP: Try that.