feat: add thumbhashes to images closes #6

This commit is contained in:
2023-08-11 16:13:20 +02:00
parent 6dd8575b15
commit 0acbbd6905
22 changed files with 489 additions and 51 deletions

17
lib/thumbhash.ts Normal file
View File

@@ -0,0 +1,17 @@
import * as thumbhash from "https://esm.sh/thumbhash@0.1.1";
export function generateThumbhash(buffer: Uint8Array, w: number, h: number) {
return thumbhash.rgbaToThumbHash(w, h, buffer);
}
export function generateDataURL(hash: string) {
const decodedString = atob(hash);
// Create Uint8Array from decoded string
const uint8Array = new Uint8Array(decodedString.length);
for (let i = 0; i < decodedString.length; i++) {
uint8Array[i] = decodedString.charCodeAt(i);
}
return thumbhash.thumbHashToDataURL(uint8Array);
}