import { createCanvas } from "https://deno.land/x/canvas/mod.ts";
export default async function(req: Request): Promise<Response> {
const width = 200;
const height = 200;
const canvas = createCanvas(width, height);
const ctx = canvas.getContext("2d");
if (ctx) {
ctx.fillStyle = "blue";
ctx.fillRect(50, 50, 100, 100);
const buffer = canvas.toBuffer("image/png");
return new Response(buffer, {
headers: { "Content-Type": "image/png" },
});
} else {
return new Response("Unable to create canvas context", { status: 500 });
}
}