Skip to content

Instantly share code, notes, and snippets.

@csinchok
Created December 13, 2013 21:39
Show Gist options
  • Save csinchok/7951812 to your computer and use it in GitHub Desktop.
Save csinchok/7951812 to your computer and use it in GitHub Desktop.
function computeAspectRatio(_w, _h) {
if (_w !== 0 && _h !== 0) {
var aspectRatio = Math.ceil(_w/_h * 10);
//smooth out rounding issues.
switch (aspectRatio) {
case 30:
case 31:
crop = "3x1";
break;
case 20:
crop = "2x1";
break;
case 14:
crop = "4x3";
break;
case 18:
crop = "16x9";
break;
case 8:
crop = "3x4";
break;
case 10:
crop = "1x1";
break;
default:
crop = "original";
}
return crop;
}
else {
return "16x9"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment