portfolio/app/api/og-image/route.tsx

63 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-10-10 15:09:12 +00:00
import {ImageResponse} from 'next/og'
export const runtime = 'edge'
const font = fetch(new URL('/assets/Inter.ttf', import.meta.url)).then(
(res) => res.arrayBuffer()
)
const gradients = [
'radial-gradient(at right top, rgb(221, 214, 254), rgb(239, 68, 68), rgb(251, 146, 60))',
'radial-gradient(at right bottom, rgb(255, 255, 255), rgb(244, 114, 182), rgb(240, 171, 252))',
'radial-gradient(at left bottom, rgb(254, 202, 202), rgb(8, 145, 178), rgb(236, 252, 203))',
'radial-gradient(at left top, rgb(124, 58, 237), rgb(220, 252, 231), rgb(31, 41, 55))',
'radial-gradient(at left bottom, rgb(214, 211, 209), rgb(190, 242, 100), rgb(190, 242, 100))'
]
export async function GET(request: Request) {
const fontData = await font
const {searchParams} = new URL(request.url)
2024-10-10 21:32:49 +00:00
const text = searchParams.get('text')
2024-10-10 15:09:12 +00:00
return new ImageResponse(
(
<div
style={{
fontSize: 64,
fontFamily: 'Inter',
2024-10-17 19:58:15 +00:00
background: '#0a0a0a',
2024-10-10 15:09:12 +00:00
width: '100%',
height: '100%',
display: 'flex',
2024-10-11 21:01:19 +00:00
textAlign: 'left',
2024-10-10 15:09:12 +00:00
alignItems: 'center',
justifyContent: 'center',
2024-10-11 21:01:19 +00:00
lineHeight: '1.1',
padding: '0 64px'
2024-10-10 15:09:12 +00:00
}}
>
<div
style={{
backgroundImage: gradients[Math.floor(gradients.length * Math.random())],
backgroundClip: 'text',
// @ts-ignore
'-webkit-background-clip': 'text',
color: 'transparent',
}}>
2024-10-10 21:32:49 +00:00
{text}
2024-10-10 15:09:12 +00:00
</div>
</div>
),
{
width: 1200,
height: 600,
fonts: [
{
name: 'Inter',
data: fontData,
style: 'normal'
}
]
}
2024-10-10 21:32:49 +00:00
)
2024-10-10 15:09:12 +00:00
}