
Security News
NVD Concedes Inability to Keep Pace with Surging CVE Disclosures in 2025
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
The blurhash npm package is a tool for generating and decoding BlurHash strings. BlurHash is a compact representation of a placeholder for an image, which can be used to display a blurred preview while the full image is loading.
Encoding an image to a BlurHash string
This feature allows you to encode an image into a BlurHash string. The `encode` function takes the image data, width, height, and the number of components for the x and y axes as parameters.
const { encode } = require('blurhash');
const imageData = new Uint8ClampedArray([/* image data */]);
const width = 32; // width of the image
const height = 32; // height of the image
const blurHash = encode(imageData, width, height, 4, 4);
console.log(blurHash);
Decoding a BlurHash string to an image
This feature allows you to decode a BlurHash string back into an image. The `decode` function takes the BlurHash string, width, height, and an optional punch parameter to control the contrast of the output image.
const { decode } = require('blurhash');
const blurHash = 'LEHV6nWB2yk8pyo0adR*.7kCMdnj';
const width = 32; // width of the resulting image
const height = 32; // height of the resulting image
const punch = 1; // controls the contrast of the output image
const imageData = decode(blurHash, width, height, punch);
console.log(imageData);
Rendering a BlurHash string to a canvas
This feature allows you to render a decoded BlurHash string to an HTML canvas element. The code demonstrates decoding a BlurHash string and then drawing the resulting image data onto a canvas.
const { decode } = require('blurhash');
const blurHash = 'LEHV6nWB2yk8pyo0adR*.7kCMdnj';
const width = 32;
const height = 32;
const punch = 1;
const imageData = decode(blurHash, width, height, punch);
const canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext('2d');
const imageDataObject = new ImageData(imageData, width, height);
ctx.putImageData(imageDataObject, 0, 0);
document.body.appendChild(canvas);
The lqip-modern package generates low-quality image placeholders (LQIP) for images. It provides a similar functionality to BlurHash by creating a blurred, low-resolution version of an image to be used as a placeholder while the full image loads. Unlike BlurHash, which uses a compact string representation, lqip-modern generates actual image data.
The sqip package (SVG-based LQIP) generates SVG placeholders for images. It creates a simplified, abstract representation of an image using SVG, which can be used as a placeholder. This approach is different from BlurHash, which uses a string-based representation and focuses on blurring the image.
npm install --save blurhash
FAQs
Encoder and decoder for the Wolt BlurHash algorithm.
The npm package blurhash receives a total of 451,574 weekly downloads. As such, blurhash popularity was classified as popular.
We found that blurhash demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers 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
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.
Security Fundamentals
Attackers use obfuscation to hide malware in open source packages. Learn how to spot these techniques across npm, PyPI, Maven, and more.
Security News
Join Socket for exclusive networking events, rooftop gatherings, and one-on-one meetings during BSidesSF and RSA 2025 in San Francisco.