iceshrimp-legacy/packages/client/src/scripts/extract-avg-color-from-blurhash.ts
2023-07-10 21:09:07 -07:00

17 lines
387 B
TypeScript

import { getBlurHashAverageColor } from "fast-blurhash";
function rgbToHex(rgb: number[]): string {
return `#${rgb
.map((x) => {
const hex = x.toString(16);
return hex.length === 1 ? `0${hex}` : hex;
})
.join("")}`;
}
export function extractAvgColorFromBlurhash(hash: string) {
return typeof hash === "string"
? rgbToHex(getBlurHashAverageColor(hash))
: undefined;
}