Installations
npm install utif2
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
16.16.0
NPM Version
8.11.0
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
photopea
Download Statistics
Total Downloads
29,592,177
Last Day
98,204
Last Week
455,351
Last Month
2,042,764
Last Year
20,343,807
GitHub Statistics
427 Stars
141 Commits
86 Forks
14 Watching
2 Branches
6 Contributors
Bundle Size
102.07 kB
Minified
36.63 kB
Minified + Gzipped
Package Meta Information
Latest Version
4.1.0
Package Id
utif2@4.1.0
Unpacked Size
102.30 kB
Size
33.80 kB
File Count
5
NPM Version
8.11.0
Node Version
16.16.0
Publised On
06 May 2023
Total Downloads
Cumulative downloads
Total Downloads
29,592,177
Last day
6.8%
98,204
Compared to previous day
Last week
-13.7%
455,351
Compared to previous week
Last month
13.8%
2,042,764
Compared to previous month
Last year
120%
20,343,807
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
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:
1npm 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 dataifd
: 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
1function imgLoaded(e) { 2 var ifds = UTIF.decode(e.target.response); 3 UTIF.decodeImage(e.target.response, ifds[0]) 4 var rgba = UTIF.toRGBA8(ifds[0]); // Uint8Array with RGBA pixels 5 console.log(ifds[0].width, ifds[0].height, ifds[0]); 6} 7 8var xhr = new XMLHttpRequest(); 9xhr.open("GET", "my_image.tif"); 10xhr.responseType = "arraybuffer"; 11xhr.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()
1<body onload="UTIF.replaceIMG()"> 2... 3<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 dataw
: image widthh
: image heightmetadata
[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.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More