Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
decode-tiff
Advanced tools
:zap: A lightweight pure JavaScript TIFF decoder. :art:
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));
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>
decode(buffer: ArrayBuffer | Buffer, options?: { singlePage?: boolean }): TiffImage | TiffImage[]
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
- 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.MIT. See LICENSE.txt.
FAQs
Lightweight tiff decoder
The npm package decode-tiff receives a total of 85,484 weekly downloads. As such, decode-tiff popularity was classified as popular.
We found that decode-tiff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.