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

@jesses/exif-parser

v1.1.28

Published

A dependency-free library to extract Exif metadata from images.

Downloads

9

Readme

exif-parser

exif-parser is a parser for image metadata in the exif format, the most popular metadata format for jpeg and tiff images. It is written in pure Typescript and has no external dependencies. It can also get the size of jpeg images and the size of the jpeg thumbnail embedded in the exif data. It can also extract the embedded thumbnail image.

Installing

yarn add @jesses/exif-parser

Creating a parser

To start parsing exif data, create a new parser like below. Note that the buffer you pass does not have to be the buffer for the full jpeg file. The exif section of a jpeg file has a maximum size of 65535 bytes and the section seems to always occur within the first 100 bytes of the file. So it is safe to only fetch the first 65635 bytes of a jpeg file and pass those to the parser.

The buffer you pass to create can be a node buffer or a DOM ArrayBuffer. Note that the parse method throws an Error when the data passed in is not valid JPEG data.

var parser = require('exif-parser').create(buffer);
try {
  var result = parser.parse();
} catch(err) {
  // got invalid data, handle error
}

Setting the flags

Before calling parse, you can set a number of flags on the parser, telling it how to behave while parsing.

Add fields in the binary format to result. Since these fields are mostly used for internal fields like Padding, you generally are not interested in these. If enabled, values for these fields will be a Buffer object in node or an ArrayBuffer in DOM environments (browsers).

parser.enableBinaryFields([boolean]), default false;

EXIF tags are organized into different sections, and to tell you the offset to other sections, EXIF uses certain tags. These tags don't tell you anything about the image, but are more for parsers to find out about all tags. Hence, these "pointer" fields are not included in the result tags field by default. Change this flag to include them nonetheless.

parser.enablePointers([boolean]), default false;

Resolve tags to their textual name, making result.tags a dictionary object instead of an array with the tag objects with no textual tag name.

parser.enableTagNames([boolean]), default true;

Read the image size while parsing.

parser.enableImageSize([boolean]), default true;

Read the EXIF tags. Could be useful to disable if you only want to read the image size.

parser.enableReturnTags([boolean]), default true;

EXIF values can be represented in a number of formats (fractions, degrees, arrays, ...) with different precision. Enabling this tries to cast values as much as possible to the appropriate javascript types like number, Date.

parser.enableSimpleValues([boolean]), default true;

working with the result

Getting the tags

The tags that were found while parsing are stored in result.tags unless you set parser.enableReturnTags(false). If parser.enableTagNames is set to true, result.tags will be an object with the key being the tag name and the value being the tag value. If parser.enableTagNames is set to false, result.tags will be an array of objects containing section, type and value properties.

Getting the image size

If parser.enableImageSize is set to true, result.getImageSize() will give you the image size as an object with width and height properties.

Getting the thumbnail

You can check if there is a thumbnail present in the exif data with result.hasThumbnail(). Exif supports thumbnails is jpeg and tiff format, though most are in jpeg format. You can check if there is a thumbnail present in a give format by passing the mime type: result.hasThumbnail("image/jpeg").

You can also get the image size of the thumbnail as an object with width and height properties: result.getThumbnailSize().

To get the node buffer or ArrayBuffer containing just the thumbnail, call result.getThumbnailBuffer()

Running the unit tests

Install nodeunit globally from npm if you haven't done so already. You can run the tests with nodeunit test/test-*.js.

Contributions

I welcome external contributions through pull requests. If you do so, please don't use regular expressions. I don't like them, and don't want to maintain a project where they are used. Also, when fixing a bug please provide a regression unit test if it makes sense.