mirror of
https://github.com/kremalicious/portfolio.git
synced 2024-12-23 01:29:41 +01:00
12 lines
548 B
TypeScript
12 lines
548 B
TypeScript
// Pixel GIF code adapted from https://stackoverflow.com/a/33919020/266535
|
|
const keyStr =
|
|
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
|
|
const triplet = (e1: number, e2: number, e3: number) =>
|
|
keyStr.charAt(e1 >> 2) +
|
|
keyStr.charAt(((e1 & 3) << 4) | (e2 >> 4)) +
|
|
keyStr.charAt(((e2 & 15) << 2) | (e3 >> 6)) +
|
|
keyStr.charAt(e3 & 63)
|
|
|
|
export const rgbDataURL = (r: number, g: number, b: number) =>
|
|
`data:image/gif;base64,R0lGODlhAQABAPAA${triplet(0, r, g) + triplet(b, 255, 255)}/yH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==`
|