npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

exifer

v1.0.0-beta.2

Published

A lightweight Exif image meta-data decipher

Downloads

336

Readme

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.

Learn more about exif tags

Features

  • 📦 Lightweight: Small with zero Dependencies
  • 🔍 Extract Exif, GPS, XMP and IPTC
  • 📷 Files: Support both JPEG and TIFF files
  • 📚 Add-ons: Extra tags and parsers available
  • ♻️ Isomorphic: Works in node.js and the browser

This module exposes three module definitions:

  • ES Module: dist/exifer.mjs
  • UMD: dist/exifer.umd.js
  • CommonJS: dist/exifer.js

Install

$ npm install exifer

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.

To read or parse more tags chekcout opts.tags.

input

Type: Buffer|ArrayBuffer|File

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);

Example running in node.js reading a JPEG Buffer:

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 timestamp
const 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 = await exifer(buffer, {tags: { gps }});
// {
//    ...
//    GPSLatitudeRef: 'N',
//    GPSTimeStamp: 1970-01-01T19:06:58.000Z
//    ...
// }
}
opts.tags.exif

Type: object default: {}

Hash-map with additonal exif tags.

OBS: Find list of exif tags here

opts.tags.iptc

Type: object default: {}

Hash-map with additonal IPTC tags.

OBS: Find list of IPTC tags here

opts.tags.gps

Type: object default: {}

Hash-map with additonal GPS tags.

OBS: Find list of exif tags here

Add-ons

If you want to read all tags the following exifer add-on packages have you covered:

To read and parse all exif and tiff tags using add-ons, you simply import and pass them to the corresponding tags option:

import exifer from 'exifer';
import iptc from '@exifer/iptc';
import exif from '@exifer/exif';
import fs from 'fs';

const buffer = fs.readFileSync('photo.jpg');
const parsed = await exifer(buffer, {tags: { exif, iptc }});

options.skipexif

Type: boolean Default: false

Skip exif tags.

options.skipiptc

Type: boolean Default: false

Skip IPTC tags.

options.skipxmp

Type: boolean Default: false

Skip XMP tags.

Tag

Type: Object

Exifer only comes with a few built-in tags. None of the default tag objects have parsers associated with them.

Example with a rather useless parser:

{name: 'ModifyDate', raw: false, parse: x => `date is ${x}`}

tag.name

Type: String

Required tag name. This is used as the key in the returned result object from exifer.

OBS: name is the only required porperty.

tag.raw

Type: Boolean Default: false

By default all tags are interpreted as ASCII strings. Set raw to true to get the raw tag value.

tag.parse

Type: Function

Custom parser function. Use this to transform tag values. Input is a ASCII string unless raw is true.

The returned output is used in the final result object returned by exifer.

Credit

Inspired by exif-orientation and ExifReader.

License

MIT © Terkel Gjervig