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

utif2

v4.1.0

Published

Fast and advanced TIFF decoder

Downloads

1,841,969

Readme

UTIF2

This is newer version of UTIF

Since last update of UTIF was 18/6/2019 and Photopea does not touch npm at all and neither 3rd party developer is keeping package up to date with GitHub repo... this package is just updated version of utif (from npm) but with many improvements.

About

A small, fast and advanced TIFF / EXIF (+ DNG, CR2, NEF and other TIFF-ish files) decoder and encoder. It is the main TIFF library for Photopea image editor. Try to open your TIFF file with Photopea to see, if UTIF.js can parse it.

  • Supports Black & White, Grayscale, RGB and Paletted images
  • Supports Fax 3 and Fax 4 (CCITT), JPEG, LZW, PackBits and other compressions (1,3,4,5,6,7,8,32773,32809)
  • E.g. this 8 MPix image with Fax 4 compression is just 56 kB ( Open in Photopea )

For RAW files, UTIF.js only decodes raw sensor data (and JPG previews, if there are any). It does not convert the raw data into a displayable image (RGBA). Such conversion is complex and out of scope of this library.

Installation

Download and include the UTIF.js file in your code. If you're in NodeJS or otherwise using NPM, run:

npm install utif

UTIF.decode(buffer)

  • buffer: ArrayBuffer containing TIFF or EXIF data
  • returns an array of "IFDs" (image file directories). Each IFD is an object, keys are "tXYZ" (XYZ is a TIFF tag number), values are values of these tags. You can get the the dimension (and other properties, "metadata") of the image without decompressing pixel data.

UTIF.decodeImage(buffer, ifd)

  • buffer: ArrayBuffer containing TIFF or EXIF data
  • ifd: the element of the output of UTIF.decode()
  • If there is an image inside the IFD, it is decoded and three new properties are added to the IFD:
    • width: the width of the image
    • height: the height of the image
    • data: decompressed pixel data of the image

TIFF files may have various number of channels and various color depth. The interpretation of data depends on many tags (see the TIFF 6 specification). The following function converts any TIFF image into a 8-bit RGBA image.

UTIF.toRGBA8(ifd)

  • ifd: image file directory (element of "ifds" returned by UTIF.decode(), processed by UTIF.decodeImage())
  • returns Uint8Array of the image in RGBA format, 8 bits per channel (ready to use in context2d.putImageData() etc.)

Example

function imgLoaded(e) {
  var ifds = UTIF.decode(e.target.response);
  UTIF.decodeImage(e.target.response, ifds[0])
  var rgba  = UTIF.toRGBA8(ifds[0]);  // Uint8Array with RGBA pixels
  console.log(ifds[0].width, ifds[0].height, ifds[0]);
}

var xhr = new XMLHttpRequest();
xhr.open("GET", "my_image.tif");
xhr.responseType = "arraybuffer";
xhr.onload = imgLoaded;   xhr.send();

Use TIFF images in HTML

If you are not a programmer, you can use TIFF images directly inside the <img> element of HTML. Then, it is enough to call UTIF.replaceIMG() once at some point.

UTIF.replaceIMG()

<body onload="UTIF.replaceIMG()">
...
<img src="image.tif" />  <img src="dog.tif" /> ...

And UTIF.js will do the rest. Internally, the "src" attribute of the image will be replaced with a new URI of the image (base64-encoded PNG). Note, that you can also insert DNG, CR2, NEF and other raw images into HTML this way.

Encoding TIFF images

You should not save images into TIFF format in the 21st century. Save them as PNG instead (e.g. using UPNG.js). If you still want to use TIFF format for some reason, here it is.

UTIF.encodeImage(rgba, w, h, metadata)

  • rgba: ArrayBuffer containing RGBA pixel data
  • w: image width
  • h: image height
  • metadata [optional]: IFD object (see below)
  • returns ArrayBuffer of the binary TIFF file. No compression right now.

UTIF.encode(ifds)

  • ifds: array of IFDs (image file directories). An IFD is a JS object with properties "tXYZ" (where XYZ are TIFF tags)
  • returns ArrayBuffer of binary data. You can use it to encode EXIF data.

Dependencies

TIFF format sometimes uses Inflate algorithm for compression (but it is quite rare). Right now, UTIF.js calls Pako.js for the Inflate method.