• Stars
    star
    182
  • Rank 211,154 (Top 5 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Rust and WASM implementation of the blurhash algorithm

blurhash-wasm

A Rust implementation of the blurhash algorithm.

It is compiled to WebAssembly (WASM), and available on npm as blurhash-wasm.

BlurHash is an algorithm written by Dag ร…gren and folks at Wolt (woltapp/blurhash). BlurHash is "a compact representation of a placeholder for an image." It enables you to store that representation in your database. It can then be transferred together with the initial data, in order to decode and show it, before the main image request has finished (or even started).

Online Demo.

Usage in JS

Installation

You will need a package manager, either npm (comes with node) or yarn.

You will also need a bundler, webpack or Rollup, configured for your project.

Then, in a terminal:

npm install blurhash-wasm
# Or, yarn add blurhash-wasm

The demo app source has a complete example of using blurhash-wasm.

decode

import * as blurhash from "blurhash-wasm";

// You can use this to construct canvas-compatible resources
try {
  const pixels = blurhash.decode("LKO2?U%2Tw=w]~RBVZRi};RPxuwH", 40, 30);
} catch (error) {
  console.log(error);
}

encode

Implented, aim to be published in 0.3.0

Usage in Rust

Installation

You will need Rust and Cargo.

Add the version you want to Cargo.toml:

[dependencies]
blurhash-wasm = "0.1.0"

decode

use blurhash_wasm;

// Result<Vec<u8>, blurhash::Error>
let res = blurhash::decode("LKO2?U%2Tw=w]~RBVZRi};RPxuwH", 40, 30);

encode

Implented, aim to be published in 0.3.0

About the setup

Based on the rust wasm-pack template

This template is designed for compiling Rust libraries into WebAssembly and publishing the resulting package to NPM.

Be sure to check out other wasm-pack tutorials online for other templates and usages of wasm-pack.

๐Ÿšด Usage

๐Ÿ› ๏ธ Build with wasm-pack build

wasm-pack build

๐Ÿ”ฌ Test in Headless Browsers with wasm-pack test

wasm-pack test --headless --firefox

๐ŸŽ Publish to NPM with wasm-pack publish

wasm-pack publish

๐Ÿ”‹ Batteries Included

More Repositories

1

react-lazy-images

๐Ÿ–ผ๏ธ ๐Ÿ›‹๏ธ Components and utilities for lazy image loading in React
TypeScript
262
star
2

eleventy-with-vite

This is a template (or demo) for integrating Vite with Eleventy.
JavaScript
95
star
3

ephemeralnotes

Ephemeral is a Progressive Web App for writing down words and their translations, as you encounter them.
Elm
44
star
4

ephemeral

(Archived) A progressive web app for writing down words and translations as you encounter them.
Elm
35
star
5

blurhash-img

A Web Component for decoding blurhash strings onto a canvas.
JavaScript
20
star
6

org-release-announcer-twitter

๐Ÿค– ๐ŸŽ‰ GitHub App to announce releases to Twitter from an org or repo.
JavaScript
9
star
7

accessible-pipeline

Accessibility monitoring, made easy
TypeScript
8
star
8

elm-flickr-gallery

Gallery app demonstrating chained HTTP requests in Elm 0.18
Elm
5
star
9

micro-anki

Anki exports as a microservice
JavaScript
4
star
10

react-faux-button

Accessible React <button> usurper.
TypeScript
3
star
11

react-a11y-tooltip

Accessible React Tooltip component
TypeScript
3
star
12

eleventy-img-example

An example of using Eleventy's eleventy-img plugin
JavaScript
2
star
13

reverie-api

The API backend for the Reverie application
Elixir
2
star
14

metalsmith-inline-critical-css

A Metalsmith plugin to inspect HTML files, inline used selectors from specified CSS, and load the rest asynchronously.
TypeScript
1
star
15

picks-bans

A simple "picks and bans" system, in Elm
Elm
1
star
16

nlpstuff

Here's where I deposit various NLP-related scripts, inspired by topics in my Postgraduate course.
Python
1
star
17

proto

Develop sites. Pick the things you need to focus on, and forget about the rest.
JavaScript
1
star
18

reverie

Reverie is a Progressive Web App for taking notes.
JavaScript
1
star
19

aroundedinburgh

The Around Project helps people discover cool places in their city. This is the first implementation, for Edinburgh.
Elixir
1
star
20

elm-pwa-basic-starter

Template to handle offline assets and PWA manifest, using webpack, in Elm
1
star
21

elm-donate-demo

Elm
1
star
22

keeping-sites-accessible

1
star