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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { fetch } from "https://esm.town/v/std/fetch";
export let canvasText = async (req: Request) => {
const query = new URL(req.url).searchParams;
const { loadImage, createCanvas } = await import(
"https://deno.land/x/canvas/mod.ts"
);
const canvas = createCanvas(1200, 675);
const ctx = canvas.getContext("2d");
let canvasWidth = canvas.width;
let canvasHeight = canvas.height;
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.fillStyle = "#6CBE45";
ctx.beginPath();
ctx.arc(canvasWidth / 2, canvasHeight / 2, 300, 0, 2 * Math.PI);
ctx.fill();
// ctx.fillRect(0, 0, canvasWidth, canvasHeight);
// Assuming query.get("headline") is the parameter you're using
const status = query.get("status");
if (status === "ok") {
ctx.fillStyle = "#ffffff"; // Text color
ctx.font = "400 300px Arial"; // Simple font
ctx.fillText(":)", 400, 430); // Adjust text position and query parameter key as needed
} else {
ctx.fillStyle = "#ffffff"; // Text color
ctx.font = "400 300px Arial"; // Simple font
ctx.fillText(":(", 400, 430); // Adjust text position and query parameter key as needed
}
// Optional: Draw an image
// If you have an image URL parameter, you can load and draw it like this:
// const imgBase64 = await fetchRemote(query.get("img"));
// const img = await loadImage(imgBase64);
// ctx.drawImage(img, 50, 200, 100, 100); // Adjust position and size as needed
return new Response(canvas.toBuffer(), {
headers: {
"Content-Type": "image/png",
},
});
};