5

Can I know an image dpi (horizontal and vertical resolution) using javascript ?

Tinku
  • 1,592
  • 1
  • 15
  • 27

2 Answers2

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