Last active
November 1, 2020 16:39
-
-
Save tcodes0/c8fd08c7d1a50c6ea1ca1a6eda929f57 to your computer and use it in GitHub Desktop.
ppi calc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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