Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@thi.ng/pixel-io-tiff

npm version npm downloads Mastodon Follow

Note

This is one of 215 standalone projects, maintained as part of the @thi.ng/umbrella ecosystem and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me. Thank you! ❤️

About

Basic TIFF image format support for @thi.ng/pixel.

This lightweight package (~2.6KB brotli) current only supports read access and the following TIFF features:

  • Metadata: Multiple IFDs (tag directories), optional Exif, GPS, Sub-IFDs extraction
  • Compression: uncompressed or deflate
  • Color formats: Grayscale 8/16 bits, (A)RGB 8bit
  • Data layout: Tiled or strips, sub-images

The following functions are included:

  • readIFDs(): Only read image metadata directories (incl. Exif/GPS if available), without parsing any pixel data. Parsing of nested IFDs can be disabled.
  • readTIFF(): Read TIFF image and parse pixel data. If an IFD is given, only the related sub-image will be read (else the main image is used).
  • intBufferFromTIFF(): Converts a parsed raw TIFF to a @thi.ng/pixel buffer

Status

ALPHA - bleeding edge / work-in-progress

Search or submit any issues for this package

Installation

yarn add @thi.ng/pixel-io-tiff

ESM import:

import * as pit from "@thi.ng/pixel-io-tiff";

Browser ESM import:

<script type="module" src="https://esm.run/@thi.ng/pixel-io-tiff"></script>

JSDelivr documentation

For Node.js REPL:

const pit = await import("@thi.ng/pixel-io-tiff");

Package sizes (brotli'd, pre-treeshake): ESM: 2.56 KB

Dependencies

Note: @thi.ng/api is in most cases a type-only import (not used at runtime)

API

Generated API docs

Basic usage

import {
    intBufferFromTIFF,
    readIFDs,
    readTIFF,
    Tag,
    Exif,
    type IFD,
} from "@thi.ng/pixel-io-tiff";
import { readBinary } from "@thi.ng/file-io";

// load as Uint8Array
const buf = readBinary("example.tiff");

// read metadata directories of all sub-images in the loaded TIFF (byte array)
// (this op does only deals with metadata and does NOT parse any pixel data)
// (options shown here are defaults)
const ifd = readIFDs(buf, { float: true, subIFD: true, all: true });

// the first IFD in a TIFF always refers to the main image
console.log(ifd);
// [
//   {
//       "256": [ 1920 ],
//       "257": [ 1473 ],
//       "258": [ 16, 16, 16 ],
//       "259": [ 8 ],
//       "262": [ 2 ],
//       "271": "Apple",
//       "272": "iPhone 11",
//       ...
//   },
//   { ... }
// ]

// access specific metadata tags
// (tag values are always arrays, strings or arrays of sub-IFDs)
console.log("size", ifd[0][Tag.ImageWidth][0], ifd[0][Tag.ImageLength][0]);
// size 1920 1473

// access Exif metadata
const exif = <IFD>ifd[0][Tag.Exif][0];
console.log(
    "exif",
    exif[Exif.FNumber][0],
    exif[Exif.ExposureTime][0],
    exif[Exif.DateTimeOriginal]
);
// exif 1.8 0.0002 2024:10:22 14:16:01

// actually parse TIFF fully and convert to thi.ng/pixel buffer
// (the given IFD is optional and can be used to just parse a sub-image (e.g. thumbnail))
const img = intBufferFromTIFF(await readTIFF(buf, ifd[0]));
// IntBuffer { size: [ 1920, 1473 ], stride: [ 1, 1920 ], format: { __packed: true, type: 'u32', ... } }

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-pixel-io-tiff,
  title = "@thi.ng/pixel-io-tiff",
  author = "Karsten Schmidt",
  note = "https://thi.ng/pixel-io-tiff",
  year = 2025
}

License

© 2025 - 2026 Karsten Schmidt // Apache License 2.0