Created
October 4, 2023 15:35
-
-
Save timc1/121a4e6c0f37510bc4ef805f9d5c42fa to your computer and use it in GitHub Desktop.
dynamic-logo.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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