EXIF metadata can be inconsistent, particularly when it comes to timestamps and location data. Many images store dates in local time without specifying a time zone, making it difficult to determine exactly when a photo was taken.
This library, built on exifr, extracts metadata from photos and aims to normalize:
- Location – Extracts GPS coordinates and identifies the time zone.
- Date & Time – Uses the time zone to determine the UTC time of the photo.
- Dimensions – Retrieves the image width and height.
Attemps are made to normalize the results from exifr
, which can vary among
image types.
Note: This package has only been tested with HEIC, PNG, and JPG files.
This package addresses a personal use case, but perhaps someone else will find it useful.
Using npm:
npm install @chriscdn/exif
Using yarn:
yarn add @chriscdn/exif
import { exif, type TExifData } from "@chriscdn/exif";
// Node.js
const image = "./path/to/file.jpg";
const data: TExifData = await exif(image);
// Browser
const file: File;
const data: TExifData = await exif(file);
This is an opinionated return value which addresses my use case. Pull requests are welcome if you require other fields to be added.
latitude
(number|null
): The latitude of the image's location in decimal degrees rounded to six significant digits. If the location is unknown, this value will benull
.longitude
(number|null
): The longitude of the image's location in decimal degrees rounded to six significant digits. If the location is unknown, this value will benull
.timeZone
(string|null
): The time zone of the location where the image was taken, which is evaluated from thelatitude
andlongitude
. If the time zone is unavailable, this will benull
.localTime
(string|null
): The local time when the image was taken (relative to the specifiedtimeZone
), formatted as an ISO 8601 string (e.g.,"2023-01-01T09:45:64"
). If the local time is unavailable, this value will benull
.timestamp
(number|null
): The Unix timestamp (in milliseconds) representing when the image was taken. If the timestamp is unavailable, this will benull
.title
(string|null
): A title of the image, if available. If no title is provided, this will benull
.caption
(string|null
): A description or caption of the image, if available. If no description is provided, this will benull
.width
(number
): The width of the image in pixels.height
(number
): The height of the image in pixels.city
(string|null
): The city where the image was taken, if available. Otherwise,null
.state
(string|null
): The state or region where the image was taken, if available. Otherwise,null
.country
(string|null
): The country where the image was taken, if available. Otherwise,null
.countryCode
(string|null
): The ISO country code of the country where the image was taken, if available. Otherwise,null
.rating
(number|null
): A numeric rating of the image, if available. Otherwise,null
.mimetype
(string|null
): The MIME type of the image (e.g.,image/jpeg
), if available. Otherwise,null
.keywords
(string[]
): An array of keywords or tags associated with the image. If no keywords are available, this will be an empty array.
The library aims to standardize differences in exifr
's output between JPG and
PNG files, based on the variations observed in my tests with files exported from
Lightroom. Additionally, it addresses
this bug by correcting the date
using the time zone or OffsetTimeOriginal
value, if either is available.
Further testing is needed for PNGs from other sources.