forked from CaliCastle/cali.so
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.ts
21 lines (20 loc) · 900 Bytes
/
image.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const shimmer = (w: number, h: number) => `
<svg width="${w}" height="${h}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" opacity="0.5">
<defs>
<linearGradient id="g-image-shimmer">
<stop stop-color="#ccc" offset="20%" />
<stop stop-color="#eee" offset="50%" />
<stop stop-color="#ccc" offset="70%" />
</linearGradient>
</defs>
<rect width="${w}" height="${h}" fill="#333" />
<rect id="r" width="${w}" height="${h}" fill="url(#g-image-shimmer)" />
<animate xlink:href="#r" attributeName="x" from="-${w}" to="${w}" dur="1s" repeatCount="indefinite" />
</svg>`
const toBase64 = (str: string) =>
typeof window === 'undefined'
? Buffer.from(str).toString('base64')
: window.btoa(str)
export function makeBlurDataURL(width: number, height: number) {
return `data:image/svg+xml;base64,${toBase64(shimmer(width, height))}`
}