I'm trying to resize image bitmap in software development, in that my requirement is as following,
- Get the original height of image
- Get the original width of image
- Set a max threshold, output height and width should be below that threshold only
My requirement is,
- output height and width should be below set threshold
- output values should be maximum possible
- The ratio of final height and width should be same as original.
I am new to this community, so pardon me if anything is incorrect, any help will be appreciate.
The maths is quite simple
For example, say you have an image with $\text{width}=6$ and $\text{height}=9$ and your threshold is $15$
The ratio between width and height is $2:3$, in other words, $$\text{width}=\frac 23\times \text{height}$$
If we increase the width to be equal to the limit, $15$, then our height becomes $$15\times \frac32 = 22.5$$
As this is above the limit of $15$, we instead set the height to be $15$ which gives us a width of $$15\times \frac 23 = 10$$
This is inside our limit so we have a new image with $\text{width}=10$ and $\text{height}=15$, which still obeys our $2:3$ ratio and is within the threshold.