# fast-blurhash **Repository Path**: ArkTSCentralRepository/fast-blurhash ## Basic Information - **Project Name**: fast-blurhash - **Description**: fast-blurhash 是一个高效且体积小的 BlurHash 解码器,提供快速的图像模糊解码功能,并支持获取图像的平均颜色。 - **Primary Language**: Unknown - **License**: ISC - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2024-11-21 - **Last Updated**: 2026-03-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # fast-blurhash 基于[fast-blurhash](https://www.npmjs.com/package/fast-blurhash)原库1.1.4版本进行适配, 所有功能代码已经转换为`ArkTS`文件 ## Install ```sh ohpm install fast-blurhash ``` ## Description > Fast & tiny [Wolt BlurHash](https://github.com/woltapp/blurhash) decoder implementation - 🤏 **Tiny**: ≈1kb minified - 🚀 **Fast**: up to 70% faster then [original `blurhash.decode`](https://github.com/woltapp/blurhash/tree/master/TypeScript#decodeblurhash-string-width-number-height-number-punch-number--uint8clampedarray) [Demo](https://mad-gooze.github.io/fast-blurhash/) ## API ### decodeBlurHash `fast-blurhash` provides a drop-in replacement for [original `blurhash.decode`](https://github.com/woltapp/blurhash/tree/master/TypeScript#decodeblurhash-string-width-number-height-number-punch-number--uint8clampedarray) ```typescript decodeBlurHash(blurhash: string, width: number, height: number, punch?: number) => Uint8ClampedArray` ``` `decodeBlurHash` uses approximate calculation for speed reasons. Results may slightly differ from original `blurhash.decode` but the diff is not noticeable (see [tests](./index.test.js)). ⚠️ `decodeBlurHash` does not validate input. #### Example ```typescript import { decodeBlurHash } from 'fast-blurhash'; // decode blurHash image const pixels = decodeBlurHash('LEHV6nWB2yk8pyo0adR*.7kCMdnj', 32, 32); // draw it on canvas const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); const imageData = ctx.createImageData(width, height); imageData.data.set(pixels); ctx.putImageData(imageData, 0, 0); document.body.append(canvas); ``` ### getBlurHashAverageColor ```typescript getBlurHashAverageColor(blurhash: string) => [number, number, number]` ``` `getBlurHashAverageColor` returns an average color of a passed blurhash image in [red, green, blue]. #### Example ```typescript import { getBlurHashAverageColor } from 'fast-blurhash'; // get image average color and use it as css background color const rgbAverageColor = getBlurHashAverageColor('LEHV6nWB2yk8pyo0adR*.7kCMdnj'); document.body.style.backgroundColor = `rgb(${rgbAverageColor.join(',')})'; ```