Summary
I have followed the guide here and produced the following file src/app/api/og/route.tsx:
import { ImageResponse } from '@vercel/og';
import { NextRequest } from "next/server";
import {deploymentURL} from "@/constant/env";
export const runtime = 'edge';
//const fontNormal = fetch(new URL("../../../../assets/SolaimanLipi.ttf", import.meta.url)).then((res) => res.arrayBuffer());
export async function GET(req: NextRequest) {
const fontData = await fetch(
new URL('../../../../assets/NotoSerifBengali-Bold.ttf', import.meta.url),
).then((res) => res.arrayBuffer());
try {
const { searchParams } = new URL(req.url);
const title = searchParams.get("title");
const description = searchParams.get("description");
const logoUrl = searchParams.get("logoUrl");
const decodedLogoUrl = logoUrl ? decodeURIComponent(logoUrl) : `${deploymentURL}/images/logo.png`;
return new ImageResponse(
(
<div style={{
width: '100%',
height: '100%',
position: "relative",
background: "red",
overflow: "hidden",
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
letterSpacing: -4,
fontFamily: '"NotoSerifBengali"',
fontWeight: 'bold'
}}>
<div style={{
width: '120%',
height: '800px',
position: "absolute",
top: '-510px',
left: '-10%',
zIndex: 10,
borderRadius: '50%',
background: '#abb2b9',
}}></div>
<div style={{
width: '110%',
height: '950px',
position: "absolute",
top: '-660px',
left: '-5%',
zIndex: 11,
borderRadius: '50%',
background: '#d6dbdf'
}}></div>
{decodedLogoUrl && (
<img src={decodedLogoUrl} alt="logo" width={200} height={200}
style={{
objectFit: 'contain',
position: "absolute",
top: 25,
left: '50%',
transform: 'translateX(-50%)',
}}/>
)}
<h1 tw="text-6xl font-bold bg-yellow-200 rounded-lg uppercase p-4 text-center absolute top-72">{title}</h1>
<p tw="text-6xl font-bold text-white text-center absolute top-100">{description}</p>
<p tw="absolute, rotate-180 top-0 left-0">Ebdresults.com</p>
</div>
),
{
fonts: [
{
name: 'NotoSerifBengali',
data: fontData,
},
],
width: 1200,
height: 630,
},
);
} catch (error: any) {
console.log(`${error.message}`);
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
return new Response(`Failed to load image: ${errorMessage}`, {
status: 500,
})
}
}