feat: add thumbhashes to images closes #6
This commit is contained in:
17
lib/thumbhash.ts
Normal file
17
lib/thumbhash.ts
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user