Can I know an image dpi (horizontal and vertical resolution) using javascript ?
Asked
Active
Viewed 8,155 times
5
-
Are you just looking for the image's size in pixels or the actual resolution of the image? – Ryan Dec 03 '09 at 13:55
-
The actual resolution of the image – Tinku Dec 03 '09 at 13:56
-
Duplicate: http://stackoverflow.com/questions/476815/can-you-access-sceen-displays-dpi-settings-in-a-javascript-function – Tim S. Van Haren Dec 03 '09 at 13:56
-
5@Tim, the question you link to asks how to get the user's screen resolution, not an image DPI. – Peter Ajtai Jun 17 '10 at 16:44
2 Answers
0
You can use the EXIF parsing extension from Blueimp's Load Image library, https://github.com/blueimp/JavaScript-Load-Image#user-content-meta-data-parsing.
loadImage.parseMetaData(file, function(meta) {
if (!meta.exif) { return; }
var resX = meta.exif.get('XResolution');
var resY = meta.exif.get('YResolution');
});
There is also the exif-js library (https://github.com/jseidelin/exif-js), but I cannot vouch for how well it works (haven't used it).

kfriend
- 2,584
- 1
- 19
- 15
-5
I think DPI is not a property of an image. DPI is a measurement used when printing.
Anyhow... You can get width and height of an image with something like this:
var image = new Image();
image.src = "http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png";
//show width and height in alert-popup
alert("Width: "+image.width+", Height: "+image.height);
The img element is always same size as the image itself, if you do not specify width and/or height. That's why this should work :)

niklas-e
- 418
- 5
- 11