temjin Posted March 27, 2008 Share Posted March 27, 2008 I made a script that uploads images to my server. It works fine for landscape orientation, but if the image is taller than it is wide, it wont upload at all. Its a really simple code so I cant figure out whats going on. Does php treat these types of images differently? Below is ALL my code, its not that long. Any ideas? <?php $type= $_POST['type']; $type= "$type/"; $orientation= $_POST['orientation']; print "$orientation"; print "$type <br />"; $status= "guest/"; $target = "images/"; $members = "members/"; $target = $target . $members . $status . $type . basename( $_FILES['userfile']['name']) ; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $target)) {print "Recieved {$_FILES['userfile']['name']}- its size is {$_FILES['userfile']['size']}"; } else { print "Upload failed!"; } imagejpeg(resizeImage(),$target,80); function resizeImage() { global $orientation; global $target; // Get the original geometry and calculate scales list($width, $height) = getimagesize($target); $scaler= 900; if ($orientation==landscape) { $scale= $scaler/$width; $new_width = round($width * ($scale)); $new_height = round($height * ($scale)); } else { $scale= $scaler/$height; $new_width = round($width * ($scale)); $new_height = round($height * ($scale)); } // Resize the original image $imageResized = imagecreatetruecolor($new_width, $new_height); $imageTmp = imagecreatefromjpeg ($target); imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } Link to comment https://forums.phpfreaks.com/topic/98120-portrait-orientation-vs-landscape/ Share on other sites More sharing options...
Cep Posted March 27, 2008 Share Posted March 27, 2008 I have re-written your function because the version you have would not work (look at your if statement). Try it, I cannot test the functionality unfortunately my IIS does not support the image functions. <?php function resizeImage($orientation, $target) { // Get the original geometry and calculate scales list($width, $height) = getimagesize($target); $scaler= 900; if ($orientation==="landscape") { $scale = $scaler / $width; $new_width = round(($width * $scale)); $new_height = round(($height * $scale)); } else { $scale = $scaler / $height; $new_width = round(($width * $scale)); $new_height = round(($height * $scale)); } // Resize the original image $imageResized = imagecreatetruecolor($new_width, $new_height); $imageTmp = imagecreatefromjpeg($target); imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height); return $imageResized; } ?> Link to comment https://forums.phpfreaks.com/topic/98120-portrait-orientation-vs-landscape/#findComment-501996 Share on other sites More sharing options...
temjin Posted March 27, 2008 Author Share Posted March 27, 2008 My function worked, but with your change I think made it more efficient. But I STILL cant upload a picture that is taller than it is wide. I really dont understand whats going on! Any more ideas? Link to comment https://forums.phpfreaks.com/topic/98120-portrait-orientation-vs-landscape/#findComment-502217 Share on other sites More sharing options...
Cep Posted March 27, 2008 Share Posted March 27, 2008 What scales are you using? I am going to hazard the guess that this is something to do with the maths involved. Heres an example of your if statement for a landscape (300h x 500w) 1.8 = 900 / 500 900 = 500 * 1.8 540 = 300 * 1.8 300h x 500w becomes 540h x 900w This seems fine but now check your portrait values for the same type of image size (500h x 300w) 3 = 900 / 300 1500 = 500 * 3 900 = 300* 3 Your new values are going to be huge in comparison, 500h x 300w becomes 1500h x 900w Perhaps and this again is a guess, your script has a restriction on the image size? Link to comment https://forums.phpfreaks.com/topic/98120-portrait-orientation-vs-landscape/#findComment-502362 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.