empty canvas from width and height in route

This commit is contained in:
2026-02-05 23:28:13 +00:00
parent 7f10714caa
commit 52d04ca392

View File

@@ -1,9 +1,22 @@
import { Hono } from 'hono'
import { createCanvas } from "@napi-rs/canvas";
import { Hono } from "hono";
const app = new Hono()
const app = new Hono();
app.get('/', (c) => {
return c.text('Hello Hono!')
})
app.get("/", (c) => c.text("go to /width/height to get a placeholder image"));
export default app
app.get("/:width/:height", async (c) => {
const width = Number.parseInt(c.req.param("width"), 10);
const height = Number.parseInt(c.req.param("height"), 10);
const canvas = createCanvas(width, height);
const ctx = canvas.getContext("2d");
ctx.fillStyle = "#ded6c4";
ctx.fillRect(0, 0, width, height);
const buffer = new Uint8Array(canvas.toBuffer("image/png"));
return c.body(buffer, 200, { "Content-Type": "image/png" });
});
export default app;