Skip to content
@deckyard/exif

Cheatsheet

Every export of @deckyard/exif, by topic, called through the import alias: import "@deckyard/exif/" as exif; then exif.read(data). tools/check-docs.sh checks each signature against the source.

A tag argument is a string: a name from the tag table ("Make"), a name with its IFD ("ifd1:XResolution"), or an IFD and a number ("gps:0x0002", "exif:42036").

Images

SignatureReturnsDoes
format(data)string"jpeg", "png" or "webp", from the first bytes; anything else throws.
hasExif(data)boolWhether the image has an EXIF segment or chunk.
read(data)ExifThe image's EXIF; an empty Exif ("be") when it has none.
readWith(data, options)Exifread with lowered caps.
write(data, x)bytesThe image with x as its EXIF; only the EXIF segment or chunk changes.
strip(data)bytesThe image without EXIF; unchanged when it has none.

Files

SignatureReturnsDoes
readFile(path)Exifread of a file.
writeFile(path, x)nullwrite into a file, replaced atomically (temporary file and rename).
stripFile(path)nullstrip a file, replaced atomically.

Payloads

SignatureReturnsDoes
parse(payload)ExifRead a bare TIFF-structured payload (II*\0... / MM\0*...).
parseWith(payload, options)Exifparse with lowered caps.
render(x)bytesSerialise to a payload: offsets computed, tags sorted, values word-aligned.

The model

Exif

FieldHolds
order as string"le" (II) or "be" (MM); write keeps it
entries as list of Entryevery tag of every IFD, without the IFD pointers and thumbnail location
thumbnail as bytesthe IFD1 JPEG, empty when there is none

Entry

FieldHolds
ifd as stringIFD0, IFD_EXIF, IFD_GPS, IFD_INTEROP or IFD1
tag as intthe tag number
type as intthe field type, TYPE_BYTE to TYPE_DOUBLE
count as intthe number of values (bytes for ASCII and UNDEFINED)
value as Valuethe value

Value

VariantPayloadHolds
Intsvalues (list of int)BYTE, SHORT, LONG, SBYTE, SSHORT, SLONG
Asciidata (bytes)ASCII, as stored, NUL included
Undefineddata (bytes)UNDEFINED
Rationalsvalues (list of Rational)RATIONAL, SRATIONAL
Floatsvalues (list of float)FLOAT, DOUBLE

Rational

FieldHolds
num as intthe numerator
den as intthe denominator; 0 is kept as read
SignatureReturnsDoes
empty(order)ExifNo entries, no thumbnail.
makeEntry(tag, type, value)EntryAn entry with an explicit type, count filled in, checked.
tagName(ifd, tag)stringThe standard name of a tag number in an IFD, "" when unknown.
describe(e)stringThe value for people: text, 1, 2, 1/125, hex for short binary data.

Entries

SignatureReturnsDoes
has(x, tag)boolWhether the tag is present.
get(x, tag)EntryThe entry; throws when absent.
set(x, entry)ExifAdd or replace an entry, kept in IFD and tag order.
remove(x, tag)ExifRemove a tag; an absent one changes nothing.
setText(x, tag, text)ExifAn ASCII tag, as UTF-8 with a closing NUL.
setInts(x, tag, values)ExifAn integer tag; SHORT or LONG tags take SHORT when the values fit.
setRationals(x, tag, values)ExifA RATIONAL or SRATIONAL tag.
setRaw(x, tag, data)ExifAn UNDEFINED tag.
text(x, tag)stringAn ASCII value up to its first NUL, as UTF-8; other bytes throw.
ints(x, tag)list of intAn integer value.
rationals(x, tag)list of RationalA rational value.
floats(x, tag)list of floatAny numeric value as floats; a zero denominator throws.
raw(x, tag)bytesAn UNDEFINED, ASCII, BYTE or SBYTE value as bytes.

Privacy and the thumbnail

SignatureReturnsDoes
removeGps(x)ExifRemove the GPS IFD.
removeThumbnail(x)ExifRemove IFD1 and its JPEG.
setThumbnail(x, jpeg)ExifSet the JPEG thumbnail; adds IFD1 Compression 6 when missing.

Readers

Gps

FieldHolds
latitude as floatdecimal degrees, north positive
longitude as floatdecimal degrees, east positive
altitude as floatmetres, negative below sea level; 0 without one
hasAltitude as boolwhether an altitude is recorded
SignatureReturnsDoes
orientation(x)intOrientation, 1 to 8.
hasGps(x)boolWhether latitude and longitude with their references are present.
gps(x)GpsThe position in decimal degrees.
setGps(x, latitude, longitude)ExifWrite latitude and longitude (and GPSVersionID when missing).
gpsTime(x)time.TimeGPSDateStamp and GPSTimeStamp, in UTC.
dateTime(x, tag, zone)time.TimeDateTimeOriginal, DateTimeDigitized or DateTime, in its OffsetTime* zone, else zone; with SubSecTime*.

Constants

ConstantValueMeaning
IFD0"ifd0"The main image's IFD.
IFD_EXIF"exif"The Exif IFD.
IFD_GPS"gps"The GPS IFD.
IFD_INTEROP"interop"The Interoperability IFD.
IFD1"ifd1"The thumbnail's IFD.
TYPE_BYTE1Unsigned 8-bit.
TYPE_ASCII2NUL-terminated text.
TYPE_SHORT3Unsigned 16-bit.
TYPE_LONG4Unsigned 32-bit.
TYPE_RATIONAL5Two unsigned 32-bit.
TYPE_SBYTE6Signed 8-bit.
TYPE_UNDEFINED7Bytes.
TYPE_SSHORT8Signed 16-bit.
TYPE_SLONG9Signed 32-bit.
TYPE_SRATIONAL10Two signed 32-bit.
TYPE_FLOAT11IEEE 754 single.
TYPE_DOUBLE12IEEE 754 double.
MAX_BYTES16777216Default cap on one EXIF payload.
MAX_ENTRIES1000Default cap on the entries of one IFD.
MAX_VALUE_BYTES1048576Default cap on one value (and the thumbnail).
MAX_NUMBERS65536Cap on the numbers all values decode to; fixed.

Errors and options

ExifError

FieldHolds
kind as stringalways "exif"
message as stringexif: and what went wrong
offset as intthe byte offset in the input, -1 when none

Options

FieldHolds
maxBytes as intpayload cap, 0 for MAX_BYTES
maxEntries as intentries per IFD, 0 for MAX_ENTRIES
maxValueBytes as intbytes per value, 0 for MAX_VALUE_BYTES

A reached cap throws an Error of kind "limit"; fs errors of the file helpers pass through unchanged.