npm install decode-tiff:zap: A lightweight pure JavaScript TIFF decoder. :art:
``sh`
npm i tiff-decode
The following example reads .tiff and converts to .png file using pngjs.
`js
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));
`
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
Drop TIFF file here!
`
- 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.TiffImage
- returns
- - 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.
-
- 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