Skip to content

Instantly share code, notes, and snippets.

@Hoyasumii
Last active September 13, 2024 18:01
Show Gist options
  • Save Hoyasumii/d72b4a2282d1c3102beceb9141a6c421 to your computer and use it in GitHub Desktop.
Save Hoyasumii/d72b4a2282d1c3102beceb9141a6c421 to your computer and use it in GitHub Desktop.
preloadImage.ts
export async function preloadImage(imageSrc: string) {
const response = await fetch(imageSrc);
const buffer = await response.arrayBuffer();
const imageBase64 = Buffer.from(buffer).toString("base64");
return `data:image/png;base64,${imageBase64}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment