wendu Posted September 1, 2009 Share Posted September 1, 2009 hey I have a PHP script that can reduce the size of an uploaded image to a percent value, but I would like a way to calculate new values for an image of any size that are at or below 1280 x 960. if I use percent values for both the width and the height, it only works on images that are of specific size. sometimes the images are bigger and thus the percent values produce a bigger image than what I said above. thank you all, big hugs! - wendu edit: to be more clear, I want my script to reduce an image's size to 1280x960 or smaller, but maintaining the aspect ratio of the image, so both vertical and horizontal images would work well.. Quote Link to comment https://forums.phpfreaks.com/topic/172733-calculating-new-size-for-images/ Share on other sites More sharing options...
ignace Posted September 1, 2009 Share Posted September 1, 2009 Not entirely sure but I think this may work: $maxWidth = 800; $maxHeight = 600; list($width, $height) = getimagesize('path/to/image'); $ratio = 1; if ($maxWidth < $width) { $ratio = $maxWidth / $width; } else if ($maxHeight < $height) { $ratio = $maxHeight / $height; } $newWidth = $width * $ratio; $newHeight = $height * $ratio; Quote Link to comment https://forums.phpfreaks.com/topic/172733-calculating-new-size-for-images/#findComment-910469 Share on other sites More sharing options...
wendu Posted September 2, 2009 Author Share Posted September 2, 2009 yeah it worked and I can even see why, it just maintains the ratio but gives the image a limit in height and width. I'm trying Quote Link to comment https://forums.phpfreaks.com/topic/172733-calculating-new-size-for-images/#findComment-910877 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.