xcandiottix Posted March 30, 2010 Share Posted March 30, 2010 I am working on a new project in which people can upload a photo to the site and the photo will be posted back up on a browse page. My question is, if someone submits a 300 w x 500 h picture, can php figure that out so pictures are no taller then 400 and no wider then 400? So in this case, php would scale the 300x500 picture proportionately down to 400 tall. I don't want to set an absolute dimension to avoid pictures being distorted but at the same time down want 2000 x 3000 images popping up. Thanks much, k.candiotti Quote Link to comment https://forums.phpfreaks.com/topic/196946-php-photo-question/ Share on other sites More sharing options...
ram4nd Posted March 30, 2010 Share Posted March 30, 2010 Well there is not a sticky for questions like this for nothing. You can do anything you want with php. Quote Link to comment https://forums.phpfreaks.com/topic/196946-php-photo-question/#findComment-1033943 Share on other sites More sharing options...
xcandiottix Posted March 30, 2010 Author Share Posted March 30, 2010 lol Oh. Should I put that between my php tags? Quote Link to comment https://forums.phpfreaks.com/topic/196946-php-photo-question/#findComment-1033946 Share on other sites More sharing options...
ram4nd Posted March 30, 2010 Share Posted March 30, 2010 Oou want to know how to do it not is it possible? Google it or look into: http://php.net/manual/en/book.image.php Quote Link to comment https://forums.phpfreaks.com/topic/196946-php-photo-question/#findComment-1033992 Share on other sites More sharing options...
oni-kun Posted March 30, 2010 Share Posted March 30, 2010 It's pointless to list code without you looking through the documentation or examples first on how to handle these things. If you're wanting exact sizes, Calculate the aspect ratio: $aspect = ($width / $height); $towidth = (400 / $aspect); Therefor, the new width will be exactly the same proportion to the height, but the height will always be 400. There'll be no distortion. Quote Link to comment https://forums.phpfreaks.com/topic/196946-php-photo-question/#findComment-1033994 Share on other sites More sharing options...
xcandiottix Posted March 30, 2010 Author Share Posted March 30, 2010 $aspect = ($width / $height); $towidth = (400 / $aspect); Therefor, the new width will be exactly the same proportion to the height, but the height will always be 400. There'll be no distortion. That's what I was getting at. I already saw everything on how to get pictures up via php, etc. But, I wasn't sure what math was involved. I read up on getimagesize() but wasn't sure what to do with that next. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/196946-php-photo-question/#findComment-1034016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.