Get back the original value of width and height from rounded values

134 Views Asked by At

I have this calculation for resizing an image in my site.

Here is the sample code:

pw = 1600 //original width
ph = 1200 //original height
mw = 200  
mh = 200

ratio = mw / float(pw)
pw = mw
ph = float(ph)* ratio

The output of this and the new width and height of the resize image is:

pw = 200 //resize width
ph = 150 //resize height

Now my problem is I don't know how to calculate and get back the original value of height and width based on the given resize value.

1

There are 1 best solutions below

7
On BEST ANSWER

You just divide the new width and height by ratio. In your case ratio$=0.125$, so $\frac {150}{0.125}=1200$ and $\frac {200}{0.125}=1600$ If you do use a floor, it will not be exact, but it will be close.