@vercel/og 0.0.13-beta.0 → 0.0.13-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -197
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Open Graph Image Generation
|
|
2
2
|
|
|
3
3
|
Generate Open Graph images with Vercel’s [Edge Function](https://vercel.com/docs/concepts/functions/edge-functions).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quick Start
|
|
6
6
|
|
|
7
|
-
Install `@vercel/og`, then use it inside
|
|
7
|
+
Install `@vercel/og`, then use it inside an API route with **Edge Runtime** configured in your Next.js project:
|
|
8
8
|
|
|
9
9
|
```jsx
|
|
10
10
|
// /pages/api/og.jsx
|
|
@@ -19,10 +19,13 @@ export default function () {
|
|
|
19
19
|
(
|
|
20
20
|
<div
|
|
21
21
|
style={{
|
|
22
|
-
fontSize: 128,
|
|
23
|
-
background: 'white',
|
|
24
22
|
width: '100%',
|
|
25
23
|
height: '100%',
|
|
24
|
+
display: 'flex',
|
|
25
|
+
alignItems: 'center',
|
|
26
|
+
justifyContent: 'center',
|
|
27
|
+
fontSize: 128,
|
|
28
|
+
background: 'lavender',
|
|
26
29
|
}}
|
|
27
30
|
>
|
|
28
31
|
Hello!
|
|
@@ -32,7 +35,11 @@ export default function () {
|
|
|
32
35
|
}
|
|
33
36
|
```
|
|
34
37
|
|
|
35
|
-
|
|
38
|
+
Then run `next dev` and access localhost:3000/api/og, the React element will be rendered and responded as a PNG from that endpoint:
|
|
39
|
+
|
|
40
|
+

|
|
41
|
+
|
|
42
|
+
Read more about the API, supported features and check out the examples in the following sections.
|
|
36
43
|
|
|
37
44
|
## API Reference
|
|
38
45
|
|
|
@@ -49,7 +56,7 @@ new ImageResponse(
|
|
|
49
56
|
options: {
|
|
50
57
|
width?: number = 1200
|
|
51
58
|
height?: number = 630
|
|
52
|
-
emoji?: 'twemoji' | 'blobmoji' | 'noto' | 'openmoji' = 'twemoji',
|
|
59
|
+
emoji?: 'twemoji' | 'blobmoji' | 'noto' | 'openmoji' | 'fluent' | 'fluentFlat' = 'twemoji',
|
|
53
60
|
fonts?: {
|
|
54
61
|
name: string,
|
|
55
62
|
data: ArrayBuffer,
|
|
@@ -75,199 +82,19 @@ When running in production, these headers will be included by `@vercel/og`:
|
|
|
75
82
|
|
|
76
83
|
During development, the `cache-control: no-cache, no-store` header is used instead.
|
|
77
84
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
## Code Examples
|
|
81
|
-
|
|
82
|
-
### Hello World
|
|
85
|
+
## Supported HTML and CSS Features
|
|
83
86
|
|
|
84
|
-
|
|
85
|
-
// /pages/api/og.jsx
|
|
86
|
-
|
|
87
|
-
import { ImageResponse } from '@vercel/og'
|
|
88
|
-
|
|
89
|
-
export const config = {
|
|
90
|
-
runtime: 'experimental-edge',
|
|
91
|
-
}
|
|
87
|
+
Please refer to [Satori’s documentation](https://github.com/vercel/satori#documentation) for a list of supported HTML and CSS features.
|
|
92
88
|
|
|
93
|
-
|
|
94
|
-
return new ImageResponse(
|
|
95
|
-
(
|
|
96
|
-
<div
|
|
97
|
-
style={{
|
|
98
|
-
fontSize: 128,
|
|
99
|
-
background: 'white',
|
|
100
|
-
width: '100%',
|
|
101
|
-
height: '100%',
|
|
102
|
-
}}
|
|
103
|
-
>
|
|
104
|
-
Hello!
|
|
105
|
-
</div>
|
|
106
|
-
)
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
```
|
|
89
|
+
## Examples
|
|
110
90
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export default async function (req) {
|
|
121
|
-
const { searchParams } = req.nextUrl
|
|
122
|
-
const username = searchParams.get('username')
|
|
123
|
-
if (!username) {
|
|
124
|
-
return new ImageResponse(<>Visit with "?username=vercel"</>)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return new ImageResponse(
|
|
128
|
-
(
|
|
129
|
-
<div
|
|
130
|
-
style={{
|
|
131
|
-
fontSize: 60,
|
|
132
|
-
color: 'black',
|
|
133
|
-
background: '#f6f6f6',
|
|
134
|
-
width: '100%',
|
|
135
|
-
height: '100%',
|
|
136
|
-
paddingTop: 50,
|
|
137
|
-
flexDirection: 'column',
|
|
138
|
-
justifyContent: 'center',
|
|
139
|
-
alignContent: 'center',
|
|
140
|
-
alignItems: 'center',
|
|
141
|
-
}}
|
|
142
|
-
>
|
|
143
|
-
<img
|
|
144
|
-
width='256'
|
|
145
|
-
height='256'
|
|
146
|
-
src={`https://github.com/${username}.png`}
|
|
147
|
-
style={{
|
|
148
|
-
borderRadius: 128,
|
|
149
|
-
}}
|
|
150
|
-
/>
|
|
151
|
-
<p>github.com/{username}</p>
|
|
152
|
-
</div>
|
|
153
|
-
)
|
|
154
|
-
)
|
|
155
|
-
}
|
|
156
|
-
```
|
|
157
|
-
|
|
158
|
-
### Emoji
|
|
159
|
-
|
|
160
|
-
```jsx
|
|
161
|
-
import { ImageResponse } from '@vercel/og'
|
|
162
|
-
|
|
163
|
-
export const config = {
|
|
164
|
-
runtime: 'experimental-edge',
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export default async function () {
|
|
168
|
-
return new ImageResponse(
|
|
169
|
-
(
|
|
170
|
-
<div
|
|
171
|
-
style={{
|
|
172
|
-
fontSize: 100,
|
|
173
|
-
color: 'black',
|
|
174
|
-
background: 'white',
|
|
175
|
-
width: '100%',
|
|
176
|
-
height: '100%',
|
|
177
|
-
padding: '0 200px',
|
|
178
|
-
textAlign: 'center',
|
|
179
|
-
justifyContent: 'center',
|
|
180
|
-
alignContent: 'center',
|
|
181
|
-
}}
|
|
182
|
-
>
|
|
183
|
-
👋, 🌎
|
|
184
|
-
</div>
|
|
185
|
-
),
|
|
186
|
-
{
|
|
187
|
-
width: 1200,
|
|
188
|
-
height: 600,
|
|
189
|
-
// Supported options: 'twemoji', 'blobmoji', 'noto', 'openmoji'
|
|
190
|
-
// Default to 'twemoji'
|
|
191
|
-
emoji: 'twemoji',
|
|
192
|
-
}
|
|
193
|
-
)
|
|
194
|
-
}
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
### Image SVG
|
|
198
|
-
|
|
199
|
-
```jsx
|
|
200
|
-
import { ImageResponse } from '@vercel/og'
|
|
201
|
-
|
|
202
|
-
export const config = {
|
|
203
|
-
runtime: 'experimental-edge',
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export default async function () {
|
|
207
|
-
return new ImageResponse(
|
|
208
|
-
(
|
|
209
|
-
<div
|
|
210
|
-
style={{
|
|
211
|
-
fontSize: 40,
|
|
212
|
-
color: 'black',
|
|
213
|
-
background: 'white',
|
|
214
|
-
width: '100%',
|
|
215
|
-
height: '100%',
|
|
216
|
-
padding: '0 200px',
|
|
217
|
-
textAlign: 'center',
|
|
218
|
-
justifyContent: 'center',
|
|
219
|
-
alignContent: 'center',
|
|
220
|
-
}}
|
|
221
|
-
>
|
|
222
|
-
<svg
|
|
223
|
-
height={80}
|
|
224
|
-
viewBox="0 0 75 65"
|
|
225
|
-
fill="black"
|
|
226
|
-
style={{ margin: '0 75px' }}
|
|
227
|
-
>
|
|
228
|
-
<path d="M37.59.25l36.95 64H.64l36.95-64z"></path>
|
|
229
|
-
</svg>
|
|
230
|
-
</div>
|
|
231
|
-
)
|
|
232
|
-
)
|
|
233
|
-
}
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### Different Languages
|
|
237
|
-
|
|
238
|
-
```jsx
|
|
239
|
-
import { ImageResponse } from '@vercel/og'
|
|
240
|
-
|
|
241
|
-
export const config = {
|
|
242
|
-
runtime: 'experimental-edge',
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export default async function () {
|
|
246
|
-
return new ImageResponse(
|
|
247
|
-
(
|
|
248
|
-
<div
|
|
249
|
-
style={{
|
|
250
|
-
fontSize: 40,
|
|
251
|
-
color: 'black',
|
|
252
|
-
background: 'white',
|
|
253
|
-
width: '100%',
|
|
254
|
-
height: '100%',
|
|
255
|
-
padding: '0 200px',
|
|
256
|
-
textAlign: 'center',
|
|
257
|
-
justifyContent: 'center',
|
|
258
|
-
alignContent: 'center',
|
|
259
|
-
}}
|
|
260
|
-
>
|
|
261
|
-
👋 Hello 你好 नमस्ते こんにちは สวัสดีค่ะ 안녕 добрий день Hallá
|
|
262
|
-
</div>
|
|
263
|
-
),
|
|
264
|
-
{
|
|
265
|
-
width: 1200,
|
|
266
|
-
height: 600,
|
|
267
|
-
}
|
|
268
|
-
)
|
|
269
|
-
}
|
|
270
|
-
```
|
|
91
|
+
- Basic · [_source_](/examples/next/pages/api/vercel.tsx) · [_demo_](https://og-examples.vercel.sh/api/vercel)
|
|
92
|
+
- Embed SVG Image · [_source_](/examples/next/pages/api/image-svg.tsx) · [_demo_](https://og-examples.vercel.sh/api/image-svg)
|
|
93
|
+
- Dynamic PNG Image Based on URL Queries · [_source_](/examples/next/pages/api/dynamic-image.tsx) · [_demo_](https://og-examples.vercel.sh/api/dynamic-image?username=vercel)
|
|
94
|
+
- Custom Font · [_source_](/examples/next/pages/api/custom-font.tsx) · [_demo_](https://og-examples.vercel.sh/api/custom-font)
|
|
95
|
+
- Emoji · [_source_](/examples/next/pages/api/emoji.tsx) · [_demo_](https://og-examples.vercel.sh/api/emoji)
|
|
96
|
+
- Languages · [_source_](/examples/next/pages/api/language.tsx) · [_demo_](https://og-examples.vercel.sh/api/language)
|
|
97
|
+
- Encrypted Token · [_source_](/examples/next/pages/api/encrypted.tsx) · [_demo_](https://og-examples.vercel.sh/encrypted/a)
|
|
271
98
|
|
|
272
99
|
## Acknowledgements
|
|
273
100
|
|
|
@@ -277,3 +104,9 @@ This project will not be possible without the following projects:
|
|
|
277
104
|
- [Twemoji](https://github.com/twitter/twemoji)
|
|
278
105
|
- [Google Fonts](https://fonts.google.com) and [Noto Sans](https://www.google.com/get/noto/)
|
|
279
106
|
- [Resvg](https://github.com/RazrFalcon/resvg) and [Resvg.js](https://github.com/yisibl/resvg-js)
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
<a aria-label="Vercel logo" href="https://vercel.com">
|
|
111
|
+
<img src="https://badgen.net/badge/icon/Made%20by%20Vercel?icon=zeit&label&color=black&labelColor=black">
|
|
112
|
+
</a>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/og",
|
|
3
|
-
"version": "0.0.13-beta.
|
|
3
|
+
"version": "0.0.13-beta.2",
|
|
4
4
|
"description": "Generate Open Graph Images dynamically from HTML/CSS without a browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"license": "MPL-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@resvg/resvg-wasm": "2.0.0-alpha.4",
|
|
24
|
-
"satori": "0.0.
|
|
24
|
+
"satori": "0.0.37",
|
|
25
25
|
"yoga-wasm-web": "0.1.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|