onthespot Posted August 10, 2009 Share Posted August 10, 2009 Hello. The following is my code for uploading a profile photo. It ensures the width is 150 and then makes the height in proportion to that. This works really well when the photo is wider than it is high. However for photos that are higher than wide, I need the code to change the height to 200, and make the width proportional. <? $profile = $_SESSION['username']; if (isset ($_FILES['new_image'])) { $imagename = $profile . '.jpg'; $source = $_FILES['new_image']['tmp_name']; $source2 = $_FILES['new_image']['name']; $target = "images/users/".$imagename; $file = explode('.', $source2); $ext = strtolower(end($file)); if ($ext != 'jpg' && $ext != 'jpeg') { echo 'Your file must be a jpeg, yours is: ' . $ext; } else { move_uploaded_file($source, $target); $imagepath = $imagename; $save = "images/users/" . $imagepath; $file = "images/users/" . $imagepath; list($width, $height) = getimagesize($file) ; $modwidth = 150; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; echo "".$_SESSION['username'].", you have changed your profile picture"; mysql_query($query); } } ?> That is my code, I need to some help with altering this to ensure that when a user uploades a photo, it is resized based on the the height or width depending on which is largest. Thankyou for reading Link to comment https://forums.phpfreaks.com/topic/169605-solved-image-height-or-width/ Share on other sites More sharing options...
onthespot Posted August 10, 2009 Author Share Posted August 10, 2009 anyone? Link to comment https://forums.phpfreaks.com/topic/169605-solved-image-height-or-width/#findComment-894824 Share on other sites More sharing options...
onthespot Posted August 10, 2009 Author Share Posted August 10, 2009 sorted it myself Link to comment https://forums.phpfreaks.com/topic/169605-solved-image-height-or-width/#findComment-894833 Share on other sites More sharing options...
tobimichigan Posted August 10, 2009 Share Posted August 10, 2009 So how did you do it? Link to comment https://forums.phpfreaks.com/topic/169605-solved-image-height-or-width/#findComment-894988 Share on other sites More sharing options...
onthespot Posted August 10, 2009 Author Share Posted August 10, 2009 Used if or else statements. If height > width else if width > height That make sense? Link to comment https://forums.phpfreaks.com/topic/169605-solved-image-height-or-width/#findComment-895134 Share on other sites More sharing options...
tobimichigan Posted August 11, 2009 Share Posted August 11, 2009 Spot, tell me.. if I were to use your code in a members area with an <> input field and after the upload display the members image on his/her area how do I do it? (Please give specific snipplets). Thanks a mil... Link to comment https://forums.phpfreaks.com/topic/169605-solved-image-height-or-width/#findComment-895471 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.