2025-09-16 17:19:58 +08:00

47 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { ImageResponse } from '@vercel/og';
import { NextRequest } from 'next/server';
export const runtime = 'edge';
export async function GET(req: NextRequest) {
try {
const { searchParams } = new URL(req.url);
const width = parseInt(searchParams.get('width') || '400');
const height = parseInt(searchParams.get('height') || '250');
if (isNaN(width) || isNaN(height) || width <= 0 || height <= 0) {
return new Response('Invalid dimensions', { status: 400 });
}
return new ImageResponse(
(
<div
style={{
width: '100%',
height: '100%',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#f3f4f6',
color: '#6b7280',
fontSize: Math.min(width, height) / 10,
fontWeight: 'bold',
}}
data-oid="h8zcpwb"
>
<div data-oid="33jg6mz">{`${width} × ${height}`}</div>
</div>
),
{
width,
height,
},
);
} catch (e) {
console.error(e);
return new Response('Failed to generate image', { status: 500 });
}
}