Complete the code to import the Next.js ImageResponse for dynamic OG images.
import { [1] } from '@vercel/og';
The ImageResponse is imported from '@vercel/og' to create dynamic OG images in Next.js.
Complete the code to define the size of the dynamic OG image.
export const runtime = 'edge'; export async function GET() { return new ImageResponse( <div style={{ width: '100%', height: '100%', backgroundColor: 'white' }}> <h1>Hello OG Image</h1> </div>, { width: [1], height: 630 } ); }
The recommended width for OG images is 1200 pixels for good display on social platforms.
Fix the error in the React component used inside ImageResponse by completing the blank.
return new ImageResponse( <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', backgroundColor: 'black', width: '100%', height: '100%' }}> <h1 style={{ color: 'white', fontSize: 72, fontWeight: 'bold' }}>[1]</h1> </div>, { width: 1200, height: 630 } );
Text inside JSX must be a string or expression. Using double quotes around the string is correct here.
Fill both blanks to create a dynamic OG image that uses a query parameter 'title' and displays it.
export async function GET(request) {
const { searchParams } = new URL(request.url);
const title = searchParams.get('[1]') || 'Default Title';
return new ImageResponse(
<div style={{ backgroundColor: 'white', width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<h1 style={{ fontSize: 64, fontWeight: 'bold' }}>{title}</h1>
</div>,
{ width: 1200, height: [2] }
);
}The query parameter key is 'title' and the height for OG images is usually 630 pixels.
Fill all three blanks to create a dynamic OG image with a blue background, white text, and font size 72.
export async function GET() {
return new ImageResponse(
<div style={{ backgroundColor: '[1]', width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<h1 style={{ color: '[2]', fontSize: [3], fontWeight: 'bold' }}>Hello Next.js OG</h1>
</div>,
{ width: 1200, height: 630 }
);
}The background color is blue, text color is white, and font size is 72 pixels for clear visibility.