mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 03:07:04 +02:00
17 lines
470 B
TypeScript
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')}`;
|
|
}
|