You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

browser-tiff.js

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-tiff.js

browser-tiff.js is a conversion of tiff.js, that nullified the require('crypto'), require('fs') inside the script when importing to web projects

1.0.1
latest
Source
npm
Version published
Maintainers
1
Created
Source

browser-tiff.js

browser-tiff.js is a direct clone of tiff.js, but with require() methods removed, so it can work without errors during 'import' and compilation for web projects.

Below are the only changes to tiff.min.js, basically Function.prototype() act like noop()

From:

... = require(...)

To:

... = Function.prototype(...)

Example Usage in Angular

  • Copy browser-tiff.d.ts to your project root folder (This is for Typescript type definition)
  • In your Angular component, use import like this:
import * as Tiff from 'browser-tiff.js';
  • Use normally as describe in original tiff.js usage below.

Original tiff.js Readme below

tiff.js

tiff.js is a port of the LibTIFF by compiling the LibTIFF C code with Emscripten.

Demo

Usage

Browser

Download tiff.min.js and load the script by yourself:

var xhr = new XMLHttpRequest();
xhr.responseType = 'arraybuffer';
xhr.open('GET', "url/of/a/tiff/image/file.tiff");
xhr.onload = function (e) {
  var tiff = new Tiff({buffer: xhr.response});
  var canvas = tiff.toCanvas();
  document.body.append(canvas);
};
xhr.send();

Node.js

$ npm install tiff.js

Example

// Usage: node this-file.js input.tiff
var Tiff = require('tiff.js');
var fs = require('fs');

var filename = process.argv[2];
var input = fs.readFileSync(filename);
var image = new Tiff({ buffer: input });
console.log(filename + ': width = ' + image.width() + ', height = ' + image.height());

API

see tiff.d.ts

Note

  • This library does not support JPEG-based compressed TIFF files
  • When you load large tiff file, you will see the error message "Cannot enlarge memory arrays in asm.js"
    • in such case, please call 'Tiff.initialize({TOTAL_MEMORY: ... })' before you create a Tiff instance
  • This JavaScript library uses only some parts of the LibTIFF features
    • To be more precise, I use following functions only
    • TIFFOpen, TIFFClose, TIFFGetField, TIFFReadRGBAImage, TIFFSetDirectory, TIFFCurrentDirectory, TIFFReadDirectory

Alternatives

License

The LibTIFF is LibTIFF Software License, zlib and additional code are zlib License.

Keywords

conversion

FAQs

Package last updated on 30 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts