[url]/api/og/route.js を書いて ImageResponse を書く。
import { ImageResponse } from "next/og";
export const runtime = "edge";
export async function GET() {
return new ImageResponse(
(
<div
style={{
fontSize: 128,
background: "white",
width: "100%",
height: "100%",
display: "flex",
textAlign: "center",
alignItems: "center",
justifyContent: "center",
}}
>
Hello world!
</div>
),
{
width: 1200,
height: 600,
}
);
}
[page]/opengraph-image.jsを書く
import { ImageResponse } from "next/server";
export const revalidate = "force-cache";
export const runtime = "nodejs";
export const alt = "OGP画像";
export const size = {
width: 1200,
height: 630,
};
export const contentType = "image/png";
export default async function Image() {
return new ImageResponse(
(
<div
style={{
fontSize: 48,
background: "white",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
width: "100%",
height: "100%",
}}
>
<div
style={{ height: 40, backgroundColor: "#5AC8D8", width: "100%" }}
/>
<h1
style={{
flex: 1,
maxWidth: "80%",
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
>
これはOGP画像です。
</h1>
<div
style={{ height: 40, backgroundColor: "#5AC8D8", width: "100%" }}
/>
</div>
),
{
...size,
}
);
}
上記で生成はできたが、SGのままだと生成されない。
うーむ