import { ImageResponse } from '@vercel/og'; import { NextRequest } from 'next/server'; export const runtime = 'edge'; // 为静态导出生成参数 export async function generateStaticParams() { // 生成常用的图片尺寸 const commonSizes = [ { width: '400', height: '250' }, { width: '800', height: '500' }, { width: '1200', height: '600' }, { width: '600', height: '400' }, { width: '300', height: '200' }, ]; return commonSizes; } export async function GET( req: NextRequest, { params }: { params: { width: string; height: string } } ) { try { // 从路径参数获取尺寸 const width = parseInt(params.width || '400'); const height = parseInt(params.height || '250'); return new ImageResponse( (
{`${width} × ${height}`}
), { width, height, }, ); } catch (e) { console.error(e); return new Response('Failed to generate image', { status: 500 }); } }