Say I'm targeting all images on a page and want to make sure that they all pass a test of being > 1:5...
This will give me the aspect ratio (from: here):
function gcd(a, b) {
return (b == 0) ? a : gcd(b, a % b);
}
var image = document.getElementById('image');
var w = image.width;
var h = image.height;
var r = gcd(w, h);
Demo: http://jsfiddle.net/f8LwL/
But how can I make sure it's > 1:5 always?