Files
blitzkit/src/core/blitzrinth/iconPng.ts
T
2024-04-20 12:00:48 -05:00

17 lines
470 B
TypeScript

import sharp from 'sharp';
const cache: Record<string, Buffer> = {};
export async function webpToPng(url: string) {
if (!url.endsWith('.webp')) return url;
if (!cache[url]) {
const imageResponse = await fetch(url);
const imageBufferWEBP = await imageResponse.arrayBuffer();
const imageBufferPNG = await sharp(imageBufferWEBP).png().toBuffer();
cache[url] = imageBufferPNG;
}
return `data:image/png;base64,${cache[url].toString('base64')}`;
}