Last active
February 11, 2023 03:25
-
-
Save bsorrentino/cf3f8a439ef688d2f869e1c00aaeecf9 to your computer and use it in GitHub Desktop.
Get DPI from javascript (live at: https://jsfiddle.net/bsorrentino/s8c51jvt/)
This file contains hidden or 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
// | |
// inspired by https://stackoverflow.com/a/838755/521197 | |
// | |
function getDPI() { | |
var div = document.createElement( "div"); | |
div.style.height = "1in"; | |
div.style.width = "1in"; | |
div.style.top = "-100%"; | |
div.style.left = "-100%"; | |
div.style.position = "absolute"; | |
document.body.appendChild(div); | |
var result = div.offsetHeight; | |
document.body.removeChild( div ); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks,
If you indulge me a little bit further.
It does not make sense to me to have only A DPI.
That doesn't make sense in a first place.
You have a width and a height. Not all screen have the same shape and proportions.
So, you should have a X DPI and a Y DPI.
One monitor I have is 1280x1024 on a 13x11in. Everything look weird on that monitor.
i.e. Movie/Video especially.
Strange that on printers and scanners (the good one) have all that info.
I should know. I made some of those.
As for 3D printers you also need a Z DPI.
Otherwise, you cannot phantom to produce anything worthy of the real world.
I think, I have just give my whole input on this now.
Let me know if I missed anything.