如何使用Node.js中的exif-parser模块从exif中提取GPS?

时间:2018-03-15 21:56:41

标签: javascript node.js gps exif

需要从图像中提取gps坐标。我该怎么做?我无法理解如何使用这个模块

1 个答案:

答案 0 :(得分:4)

这是一个小脚本,打印出来自exif-parser的所有信息:

const exif = require('exif-parser')
const fs = require('fs')

const buffer = fs.readFileSync(__dirname + '/ibiza.jpg')
const parser = exif.create(buffer)
const result = parser.parse()

console.log(JSON.stringify(result, null, 2))

结果:

{
  "startMarker": {
    "offset": 0
  },
  "tags": {
    "Make": "Apple",
    "Model": "iPhone 4",
    "Orientation": 1,
    "XResolution": 72,
    "YResolution": 72,
    "ResolutionUnit": 2,
    "Software": "4.3.5",
    "ModifyDate": 1315140671,
    "GPSLatitudeRef": "N",
    "GPSLatitude": 38.90983333333333,
    "GPSLongitudeRef": "E",
    "GPSLongitude": 1.4386666666666668,
    "GPSAltitudeRef": 0,
    "GPSAltitude": 0,
    "GPSTimeStamp": [
      11,
      7,
      47
    ],
    "GPSImgDirectionRef": "T",
    "GPSImgDirection": 82.12307692307692,
    "GPSDateStamp": "2011:09:04",
    "ExposureTime": 0.0003315649867374005,
    "FNumber": 2.8,
    "ExposureProgram": 2,
    "ISO": 80,
    "DateTimeOriginal": 1315140671,
    "CreateDate": 1315140671,
    "ShutterSpeedValue": 11.558659217877095,
    "ApertureValue": 2.970853573907009,
    "MeteringMode": 5,
    "Flash": 0,
    "FocalLength": 3.85,
    "ColorSpace": 1,
    "ExifImageWidth": 1024,
    "ExifImageHeight": 765,
    "SensingMethod": 2,
    "CustomRendered": 4,
    "ExposureMode": 0,
    "WhiteBalance": 0,
    "SceneCaptureType": 0
  },
  "imageSize": {
    "height": 598,
    "width": 800
  },
  "app1Offset": 24
}

使用的图片:enter image description here