Comments (11)
Diagonal in inches or pixels? Context?
from dpi.
Actually I am trying to implement this requirement: The user will define the dimensions of the buttons on my web page in cm/mm (in database) and I need to display them in these dimensions but as far as I have read I need to have the DPI of the screen in order to convert cm/mm into pixels. In the dpi.js I have found that it needs to have the diagonal value hardcoded into the function which is something I do not want. I would like to have a function which could calculate the DPI or which could finally convert the cm/mm in pixels. I am trying to implement dynamic pagination on the screen and the application should display only those many buttons as there is a screen size available for that I need to first calculate the screensize in cm/mm and then I need to calculate how many buttons should I fetch from the backend.
from dpi.
Following is my issue:
var dppx = window.devicePixelRatio ||
(window.matchMedia && window.matchMedia("(min-resolution: 2dppx), (-webkit-min-device-pixel-ratio: 1.5),(-moz-min-device-pixel-ratio: 1.5),(min-device-pixel-ratio: 1.5)").matches? 2 : 1) ||
1;
var w = screen.width * dppx;
var h = screen.height * dppx;
var d = Math.sqrt(w*w + h*h);
var dpi = d / 13.3;
console.log(w, h, d, dpi);
In the above code the value 13.3 needs to be hardcoded and that is something I would like to detect by code otherwise I need to hardcode it.
http://plnkr.co/edit/CxhFhlHIYWmetH3dSM0R?p=preview
from dpi.
As per the formula https://en.wikipedia.org/wiki/Display_size I tried to calculate the diagonal size from the height and width but then the issue comes which I think is related to converting pixels to cm/mm which makes me feel I am running in circles :)
from dpi.
@zeeshanjan82 I believe you are running in circles. There's no API in the web to get the physical size of a screen, so you must hard code 13.3
. @LeaVerou Correct me if I'm wrong, but I've looked and looked, and there's no way to actually determine the PPI/DPI of a screen purely programmatically without hard coding numbers and storing them somewhere (as in the device list of this repo).
Native apps let you use EDID info from a screen in order to get the measurements of the screen, which, unfortunately, isn't exposed in web APIs.
from dpi.
Thanks @trusktr I agree but I wanted to have something very similar to what the native api provides, it does not really make sense to hard code the value.
from dpi.
@zeeshanjan82 I know, I completely agree. I made a discussion about it on Specification|Discourse a while back: http://discourse.wicg.io/t/exposing-hardware-pixel-density-and-other-screen-metrics-via-window-screen/709/15
That's a good place to talk about standards. If you could log in, and heart my topic, that could help make it eventually happen. :}
from dpi.
Sure Thanks @trusktr
from dpi.
@trusktr Sorry for the delay, but yes, you're correct. There is no API to get the physical size.
from dpi.
Isn't that lame? Don't you wish there was a standard web API for that? I definitely do!
from dpi.
Yes, it’s totally lame. The argument I've heard against it is that there is no reliable way to get that info from the OS, as the OS often doesn’t have it either.
from dpi.
Related Issues (20)
- Add a license HOT 3
- Virtual Reality makes this library VERY valuable HOT 1
- Add Tesco Hudl 2 HOT 5
- Samsung S7 and S7 Edge PPI (2560x1440) HOT 1
- DPI overview missing VR and 3D info
- How about using Heroku and logging device details? HOT 1
- Issue with correctly reading a 29" 21x9 monitor. Reads diagonal as 13.3" HOT 2
- Missleading values for iPhone 6/6S/7 Plus screens
- Incorrect value for iPhone5 HOT 1
- Inaccurate dppx values? HOT 3
- Wrong diagonal screen size calculated leading to wrong dpi HOT 1
- Galaxy S8/S8+ HOT 3
- Landscape/portrait consistency HOT 1
- xioami redmi note 4 (mido) HOT 2
- Acer x213w HOT 2
- dppx missing != unknown
- SSL certificate for HTTPS HOT 1
- Certificate expired causing a warning on modern browsers HOT 1
- Formula for calculating physical screen size not working on MacOS with system scaling
- dpi.lv does not resolve to IP address HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dpi.