Skip to content

Instantly share code, notes, and snippets.

@richarddewit
Last active April 1, 2019 10:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richarddewit/a81b27659848af1da83dc6d0429d0a97 to your computer and use it in GitHub Desktop.
Save richarddewit/a81b27659848af1da83dc6d0429d0a97 to your computer and use it in GitHub Desktop.
Calculate nearest whole size on aspect ratio
// Paste this in your JavaScript console:
var width = 1440;
var height = 500;
var minWidth = 1000;
var maxWidth = 1500;
var ar = height / width;
for (var i = minWidth; i < maxWidth; i++) {
if (ar * i % 1 === 0) {
console.log(i + 'x' + (i * ar));
}
}
/*
* Example output:
*
* 1008x350
* 1080x375
* 1152x400
* 1224x425
* 1296x450
* 1368x475
* 1440x500
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment