Friday, September 22, 2023

node.js: get EXIF info from img files

Exif - Wikipedia

Exchangeable image file format (officially Exif, according to JEIDA/JEITA/CIPA specifications)[5] is a standard that specifies formats for images, sound, and ancillary tags used by digital cameras (including smartphones), scanners and other systems handling image and sound files recorded by digital cameras.


JPEG and EXIF Data Manipulation in Javascript | Getaround Tech

EXIF Tags


Getting image metadata (EXIF) using Node.js

exif - npm search


exif-parser - npm Weekly Downloads: 830,159

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 javascript 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.


exif - npm (MIT license)

gomfunkel/node-exif: A node.js library to extract Exif metadata from images.

convert to js promise to be able to use with async/await

import exif from 'exif'
export async function getExifAsync(imgPath) {
    return new Promise(function(resolve, reject) {
        new exif.ExifImage({ image : imgPath }, function (error, exifData) {
            if (error) {
                reject(error)
            } else {
                resolve(exifData)
            }
        });
    }) }
const exifData = await getExifAsync(imgPath)
console.log(exifData)


here is another library that also provides assess to "thumbnail" image that is embedded into the EXIF


ExifReader is a JavaScript library that parses image files and extracts the metadata. It can also extract an embedded thumbnail. It can be used either in a browser or from Node. Supports JPEG, TIFF, PNG, HEIC, and WebP files with Exif, IPTC, XMP, ICC, and MPF metadata (depending on file type).


the "popularity winner", but not useful for reading EXIF


Weekly Downloads: 3,308,475Turns out the exif, iptc, and xmp fields contain the raw data, rather than parsed data. Hurm. It's an opaque object from which we cannot access the fields. This is not the hoped-for result, nor does it fit with other features in Sharp.


No comments: