-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathogImage.ts
111 lines (104 loc) · 3.65 KB
/
ogImage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import { Resvg } from '@resvg/resvg-js';
import satori from "satori";
import parseFrontMatter from "gray-matter";
export const exportAsPng = async (file: any, interFont: any) => {
const { title, description } = parseFrontMatter(file).data;
const svg = await satori(ogImage(title, description), {
width: 800,
height: 400,
fonts: [
{
name: 'Inter',
data: interFont,
weight: 400,
style: 'normal'
}
]
});
const reSvg = new Resvg(svg, {
fitTo: {
mode: "width",
value: 1200,
}
});
return reSvg.render().asPng()
}
const ogImage = (title: string, description: string = "") => ({
type: "div",
props: {
style: {
backgroundImage: "radial-gradient(circle, #000000 90%, rgba(40, 40, 40, 0.87) 97%)",
backgroundPosition: "0 0",
backgroundSize: "20px 20px",
color: "white",
height: "100%",
width: "100%",
display: "flex",
flexDirection: "column",
paddingLeft: "30",
paddingRight: "30",
fontFamily: "Inter",
position: "relative"
},
children: [
{
type: "div",
props: {
style: { marginTop: 30, fontSize: 19 },
children: "mystica.me"
}
},
{
type: "div",
props: {
style: { marginTop: 100, display: "flex", flexDirection: "column" },
children: [
{
type: "div",
props: {
style: { fontSize: 40, textTransform: "capitalize" },
children: title
},
},
{
type: "div",
props: {
style: { marginTop: 30, fontSize: 20, textTransform: "capitalize" },
children: description || ""
}
},
],
}
},
{
type: "div",
props: {
style: { marginBottom: 30, display: "flex", flexDirection: "row", width: "100%", justifyContent: "space-between", alignItems: "center", position: "absolute", bottom: "4%", left: "4%" },
children: [
{
type: "div",
props: {
children: "By Mystica"
}
},
{
type: "div",
props: {
style: { display: "flex" },
children: [{
type: "img",
props: {
width: "50",
height: "50",
src: "https://raw.githubusercontent.com/mystica2000/image-dump/main/mystica.jpg",
style: { borderRadius: "50%", objectFit: "cover", objectPosition: "20% 50%" }
}
}]
}
}
]
}
},
],
}
});