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

decode-tiff

v0.2.1

Published

Lightweight tiff decoder

Downloads

382,374

Readme

decode-tiff

npm version License: MIT

:zap: A lightweight pure JavaScript TIFF decoder. :art:

How to use it

With Node.js

npm i tiff-decode

The following example reads .tiff and converts to .png file using pngjs.

const { decode } = require("decode-tiff");

const { PNG } = require("pngjs");
const fs = require("fs");

const { width, height, data } = decode(fs.readFileSync(__dirname + "/lena_color.tiff"));

const png =  new PNG({ width, height });
png.data = data;
fs.writeFileSync(__dirname + "/lena.png", PNG.sync.write(png));

With Browser

Download script file from dist/decode-tiff.min.js. Alternatively you can use Module Bundler, such as webpack, Browserify, and Rollup.

This example shows metadata of the dropped file. Working demonstration is here.

<html>
<head></head>
<body>

  <div id="drop">
    <p>Drop TIFF file here!</p>
  </div>

<script src="decode-tiff.min.js"></script>
<script>
const { decode } = window.decodeTiff;
const elm = document.getElementById("drop");
elm.addEventListener("dragenter", e => e.preventDefault());
elm.addEventListener("dragover", e => e.preventDefault());
elm.addEventListener("drop", e => {
  e.preventDefault();
  const file = e.dataTransfer.files[0];
  const reader = new FileReader();
  reader.addEventListener("load", e => {
    const arrayBuffer = e.target.result;
    const { width, height, ifdEntries } = decode(arrayBuffer);
    const metadata = JSON.stringify({ width, height, ifdEntries }, null, 2);
    elm.innerHTML = `<pre>${metadata}</pre>`;
  });
  reader.readAsArrayBuffer(file);
});
</script>
</body>
</html>

API

decode(buffer: ArrayBuffer | Buffer, options?: { singlePage?: boolean }): TiffImage | TiffImage[]

  • params
    • buffer - Required - Buffer of the target TIFF image. Node.js Buffer and ECMA Script's ArrayBuffer are acceptable.
    • options.singlePage - Optional (default: true) - If true, this function returns a single TiffImage object. If the input has 2 or more pages, return value will be the first page.
  • returns
    • TiffImage - An object.
    • TiffImage.width - number - Width of the input image.
    • TiffImage.height - number - Height of the input image.
    • TiffImage.data - Uint8Array - Image pixel data. Every pixel consists 4 bytes: R, G, B, A (opacity)
    • TiffImage.ifdEntries - {[key: string]: Array} - Each IFD entries of the input image.

Compatibility

  • Byte Order
    • [x] Little endian
    • [x] Big endian
  • Color resolusion
    • [x] 32bit Full Colors
    • [x] 24bit Full Colors
    • [x] 8bit Gray scale
    • [x] 4bit Gray scale
    • [ ] Palette-Color
    • [ ] Bilevel(white)
    • [ ] Bilevel(black)
  • Compression
    • [x] No Compression
    • [ ] CCITT Group 3
    • [ ] LZW Compression
    • [ ] ZIP
    • [ ] Packbits
  • Masking
    • [ ] Transparency Mask

License

MIT. See LICENSE.txt.