views:

51

answers:

2

Hi,

Lets say I have a non-square image..

If I increment the width and I recalculate the height according to the incremented width (ratio), sometimes I get xxx.5 (decimals) for the width

ex.: width = 4, height = 2 I augment the width with a factor of 1.25 I'll get : width = 5 Next, the height will be : heigth = 2.5

How can I determine the nearest image format that would have integers on both sides? (bigger if possible)

Thanks

+3  A: 

Let g be the http://en.wikipedia.org/wiki/Greatest_common_divisor of w and h. The next biggest image has width w + w/g and height h + h/g. You can compute g with http://en.wikipedia.org/wiki/Euclidean_algorithm .

I don't know which to choose
Mike Gleason jr Couturier
+3  A: 

reduce the fraction to lowest terms and then multiply by integers. You reduce a/b to lowest terms by dividing each by their common gcd. If d = gcd(a,b), then (a/d) / (b/d) is in lowest terms. Now, if you want the next largest integer fraction with the same ration, then multiple the numerator and denominator by d+1. Thus,

(d+1) * (a/d) is the numerator and (d+1) * (b/d) is the denominator.

GregS
I don't know which to choose ;)
Mike Gleason jr Couturier