Skip to content

Instantly share code, notes, and snippets.

@tcodes0
Last active November 1, 2020 16:39
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 tcodes0/c8fd08c7d1a50c6ea1ca1a6eda929f57 to your computer and use it in GitHub Desktop.
Save tcodes0/c8fd08c7d1a50c6ea1ca1a6eda929f57 to your computer and use it in GitHub Desktop.
ppi calc
var TO_MILIMETER = 25.4
function calc_dpi (widthPixels: number, heightPixels: number, diagonal: float) {
var x = width
var y = height
var ratio = y/x;
var xd = Math.sqrt( Math.pow(diagonal,2) / ( 1 + Math.pow(ratio, 2) ));
var yd = xd * ratio;
var pitch = TO_MILIMETER/(x/xd);
var result = {
displayDiagonalCentimeters : diagonal * 2.54,
displayWidth : xd,
displayHeight : yd,
displayAreaSquareInches : xd*yd,
displayWidthCentimeters : 2.54*xd,
displayHeightCentimeters : 2.54*yd,
displayAreaSquareCentimeters : xd*yd * 2.54*2.54,
ppiWidth : x/xd,
ppiHeight : y/yd,
pixelPixelDistanceMilimeters : pitch,
ppiSquare : x/xd*y/yd
};
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment