I believe that you are looking for a suitable integer:integer aspect ratio, for example 16:9 , and not a float:1 solution, for example 1.77778:1 .
If yes, then you need to find the largest common factor (GCD) and divide both values ββby this. GCD is the largest number that evenly divides both numbers. Thus, the GCD for 6 and 10 is 2, the GCD for 44 and 99 is 11.
For example, a 1024x768 monitor has a GCD of 256. When you divide both values ββinto this, you get 4x3 or 4: 3.
A (recursive) GCD algorithm:
function gcd (a,b): if b == 0: return a return gcd (b, a mod b)
In C:
static int gcd (int a, int b) { return (b == 0) ? a : gcd (b, a%b); } int main(void) { printf ("gcd(1024,768) = %d\n",gcd(1024,768)); }
And here is some full HTML / Javascript that shows one way to determine screen size and calculate aspect ratio. This works in FF3, I'm not sure if other browsers support screen.width and screen.height .
<html><body> <script type="text/javascript"> function gcd (a, b) { return (b == 0) ? a : gcd (b, a%b); } var w = screen.width; var h = screen.height; var r = gcd (w, h); document.write ("<pre>"); document.write ("Dimensions = ", w, " x ", h, "<br>"); document.write ("Gcd = ", r, "<br>"); document.write ("Aspect = ", w/r, ":", h/r); document.write ("</pre>"); </script> </body></html>
It outputs (to my weird widescreen monitor):
Dimensions = 1680 x 1050 Gcd = 210 Aspect = 8:5
Others I've tested this on:
Dimensions = 1280 x 1024 Gcd = 256 Aspect = 5:4 Dimensions = 1152 x 960 Gcd = 192 Aspect = 6:5 Dimensions = 1280 x 960 Gcd = 320 Aspect = 4:3 Dimensions = 1920 x 1080 Gcd = 120 Aspect = 16:9
I am sorry that I did not have this house, but, unfortunately, this is not a working machine.
What you do if you find that the aspect ratio is not supported by the graphical resizing tool is another matter. I suspect that it is best to add lines with lettering (for example, the ones you get on top and bottom of your old TV when you watch a widescreen movie on it). I would add them at the top / bottom or on the sides (depending on which one leads to the least number of skidding lines) until the image meets the requirements.
One thing you might want to consider is image quality, which was changed from 16: 9 to 5: 4. I still remember the incredibly tall, thin cowboys I watched in my youth on TV before boxing. was submitted. You might be better off having one image per aspect ratio and just resize it to the actual screen size before sending it over the cable.