Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blurhash

Package Overview
Dependencies
Maintainers
5
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blurhash

Encoder and decoder for the Wolt BlurHash algorithm.

  • 2.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created

What is blurhash?

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.

What are blurhash's main functionalities?

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);

Other packages similar to blurhash

Keywords

FAQs

Package last updated on 17 Feb 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc