dweb Posted November 22, 2012 Share Posted November 22, 2012 hi i'm having big problems trying to figure something out, so wondering if someone can help. I have two numbers, as $width = 800; $height = 1000; these numbers are not always the same value, so they can look like $width = 700; $height = 450; and i want to reduce both numbers, keeping their ratio but i want to reduce both the values, until either one meets their min value allowed $width_max_val = 200; $height_min_val = 400; So if the values were $width = 410; $height = 750; $width_max_val = 200; $height_min_val = 400; then the outputted values would be 219 400 can anyone help? thanks Quote Link to comment Share on other sites More sharing options...
thara Posted November 22, 2012 Share Posted November 22, 2012 jquery will help you to do this.... Quote Link to comment Share on other sites More sharing options...
dweb Posted November 22, 2012 Author Share Posted November 22, 2012 i can't do that as its a php script that runs in the background, so i need to do a php calculation to achieve it Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 22, 2012 Share Posted November 22, 2012 (edited) Um, your question doesn't match your "code". You state " . . . i want to reduce both the values, until either one meets their min value allowed" But, in the variables you have $width_max_val and $height_min_val. Huh??? Then in your last example, you show that you want the results to be 219 and 400, but 219 is greater than 200 which is supposedly the min, or is it max? It just doesn't make sense. If you have a minimum for one measurement but a max for the other you could very easily have a scenario where there is no solution. But, if you really DO want to set the new measurements based upon two minimums, it is simple math. //Determine the smaller of the input to min ratio $resizeRatio = min( ($minWidth/$inputWidth), ($minHeight/$inputHeight) ); //Get new sizes based on resize ratio $newWidth = round($inputWidth * $resizeRatio); $newHeight = round($inputHeight * $resizeRatio); Edited November 22, 2012 by Psycho Quote Link to comment Share on other sites More sharing options...
codefossa Posted November 22, 2012 Share Posted November 22, 2012 (edited) // Nvm I may have misread his question. Edited November 22, 2012 by Xaotique Quote Link to comment 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.