Files
discordeno/packages/utils/src/urlToBase64.ts
Lars_und_so 8b18d06834 yes (#2714)
Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
2023-01-08 20:04:04 -06:00

10 lines
411 B
TypeScript

import { encode } from './base64.js'
/** Converts a url to base 64. Useful for example, uploading/creating server emojis. */
export async function urlToBase64(url: string): Promise<string> {
const buffer = await fetch(url).then(async (res) => await res.arrayBuffer())
const imageStr = encode(buffer)
const type = url.substring(url.lastIndexOf('.') + 1)
return `data:image/${type};base64,${imageStr}`
}