Skip to content

Instantly share code, notes, and snippets.

@timc1
Created October 4, 2023 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timc1/121a4e6c0f37510bc4ef805f9d5c42fa to your computer and use it in GitHub Desktop.
Save timc1/121a4e6c0f37510bc4ef805f9d5c42fa to your computer and use it in GitHub Desktop.
dynamic-logo.ts
import { loadCommunity } from "@lib/loadCommunity.server";
import { ImageResponse } from "@vercel/og";
import { NextRequest, NextResponse } from "next/server";
export async function GET(request: NextRequest, { params }: { params: { slug: string; size: string } }) {
const community = await loadCommunity(params.slug);
if (!community || !community.icon_url) {
return NextResponse.json(
{ message: "Not found" },
{
status: 404,
}
);
}
const size = Number(params.size);
return new ImageResponse(
(
<img
src={community.icon_url}
width={size}
height={size}
style={{
objectFit: "cover",
}}
/>
),
{
height: size,
width: size,
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment