1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { createCanvas } from "https://deno.land/x/canvas/mod.ts";
export default async function(req: Request): Promise<Response> {
const width = 200;
const height = 200;
// Create a new canvas
const canvas = createCanvas(width, height);
const ctx = canvas.getContext("2d");
// Draw a blue rectangle on the canvas
if (ctx) {
ctx.fillStyle = "blue";
ctx.fillRect(50, 50, 100, 100); // Adjust the rectangle position and size as needed
// Convert the canvas content to a PNG buffer
const buffer = canvas.toBuffer("image/png");
// Return a response with the PNG image
return new Response(buffer, {
headers: { "Content-Type": "image/png" },
});
} else {
return new Response("Unable to create canvas context", { status: 500 });
}
}