A lightweight exif image meta-data decipher
Exifer is a small module that read JPEG/TIFF meta-data.
Exif tags/fields are used to encode additional information into images taken by digital still cameras. The exif meta information is organized into different Image File Directories (IFD's) within the image. It contains useful information like image rotation, GPS coordinates, times stamps. ISO, etc.
The script can also be directly included from unpkg.com:
<script src="https://unpkg.com/exifer"></script>
Usage
import exifer from 'exifer'import fs from 'fs';const buffer = fs.readFileSync('photo.jpg');;const tags = await exifer(buffer);// {// Make: 'Apple',// Model: 'iPhone X',// Orientation: 6,// Software: '12.4',// ModifyDate: '2019:08:25 15:07:02',// ... and so on// }
API
exifer(input, [opts])
Returns: object <Promise>
Takes a JPEG or JIFF image as input and returns an object with extracted meta-data. A Promise is returned that resolves to an hash-map of tag/value pairs.
Exifer only reads the most essential tags out of the box – which should cover 99% of all use cases. Tags are by default interpreted as ASCII strings.
Example running in the browser reading a File (ArrayBuffer):
import exifer from 'exifer';/** * Assume 'input' is the value coming from an input field: * <input type="file" accept="image/*" id="input" > */const input = document.getElementById('#input').files[0];const tags = await exifer(input);
import exifer from 'exifer';import fs from 'fs';const buffer = fs.readFileSync('photo.jpg');;const tags = await exifer(buffer);
opts.tags
Type: object
Exifer does not extract more than the most essential tags.
You can extract additional tags, or overwrite the default tags, if you want to read more tags or write custom parsers. You can do this by passing tag objects to either tags.exif, tags.gps and/or tags.iptc.
The key for additional IFD image tags is the IFD field code in hexadecimal notation. The value is a tag object with at least a name property.
Here's an example where two custom gps tag objects passed as tags.gps:
import exifer from 'exifer';import fs from 'fs';// try to read more GPS tags and parse timestampconst gps = { 0x0001: {name: 'GPSLatitudeRef'}, 0x0007: {name: 'GPSTimeStamp', parse: x => { return new Date(Date.UTC(1970, 0, 1, x[0], x[1], x[2])); }}}const buffer = fs.readFileSync('photo.jpg');const parsed =