mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 03:29:51 +02:00
15 lines
430 B
TypeScript
15 lines
430 B
TypeScript
import sharp from 'sharp';
|
|
|
|
const cache: Record<string, string> = {};
|
|
|
|
export async function iconPng(url: string) {
|
|
if (cache[url]) return cache[url];
|
|
|
|
const imageResponse = await fetch(url);
|
|
const imageBufferWEBP = await imageResponse.arrayBuffer();
|
|
const imageBufferPNG = await sharp(imageBufferWEBP).png().toBuffer();
|
|
cache[url] = `data:image/png;base64,${imageBufferPNG.toString('base64')}`;
|
|
|
|
return cache[url];
|
|
}
|