mcnaveen / blurhash-from-url

πŸ¦„ Simple utility to generate blurhash from Image URL

Home Page:https://npmjs.com/package/blurhash-from-url

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generate Blurhash from Image URL

πŸ¦„ Simple utility to generate blurhash from Image URL

Test Downloads this Week Bundle Size Version

Blurhash from URL

πŸ“¦ Requirements

  • Node.js 16X LTS or Higher πŸ“¦

✨ Installation

  • Install the NPM Package with the below command:
npm install blurhash-from-url --save

(or)

  • Install with Yarn:
yarn add blurhash-from-url

πŸ’‘ Usage Example

  • Import it in your project
  • Pass the URL of the image
  • Make sure to use Async/Await function
//ES6 Import
import { blurhashFromURL } from "blurhash-from-url";

// Commonjs Import
// const { blurhashFromURL } = require("blurhash-from-url");

async function getBlurhash() {
  const output = await blurhashFromURL("https://i.imgur.com/NhfEdg2.png");
  console.log(output);
}

getBlurhash();

β˜‘οΈ Example Output

{
  encoded: 'UnR.*,kW.TnPt7WBocozpJV@nMkWadofWCV@',
  decoded: Uint8ClampedArray(1440000) [
    255, 255, 251, 255, 255, 255, 251, 255, 255, 255, 251, 255,
    255, 255, 251, 255, 255, 255, 251, 255, 255, 255, 251, 255,
    255, 255, 251, 255, 255, 255, 251, 255, 255, 255, 251, 255,
    255, 255, 251, 255, 255, 255, 250, 255, 255, 255, 250, 255,
    255, 255, 250, 255, 255, 255, 250, 255, 255, 255, 250, 255,
    255, 255, 250, 255, 255, 255, 250, 255, 255, 255, 250, 255,
    255, 255, 250, 255, 255, 255, 250, 255, 255, 255, 250, 255,
    255, 255, 250, 255, 255, 255, 250, 255, 255, 255, 250, 255,
    255, 255, 250, 255,
    ... 1439900 more items
  ],
  width: 600,
  height: 600
}

Optional Size Parameter

By default, the image is resized to 32x32. You can pass the size as an optional parameter.

async function getBlurhash() {
  const output = await blurhashFromURL("https://i.imgur.com/NhfEdg2.png", {
    size: 64,
  });
  console.log(output);
}

πŸ’š Message

I hope you find this useful. If you have any questions, please create an issue.

About

πŸ¦„ Simple utility to generate blurhash from Image URL

https://npmjs.com/package/blurhash-from-url


Languages

Language:TypeScript 68.7%Language:JavaScript 31.3%