29 lines
756 B
TypeScript
29 lines
756 B
TypeScript
#!/usr/bin/env bun
|
|
|
|
import { createCanvas } from "canvas";
|
|
import { join } from "node:path";
|
|
|
|
// Create a 200x200 canvas
|
|
const canvas = createCanvas(200, 200);
|
|
const ctx = canvas.getContext("2d");
|
|
|
|
// Fill background with white
|
|
ctx.fillStyle = "white";
|
|
ctx.fillRect(0, 0, 200, 200);
|
|
|
|
// Draw a red circle in the center
|
|
ctx.fillStyle = "red";
|
|
ctx.beginPath();
|
|
ctx.arc(100, 100, 50, 0, Math.PI * 2);
|
|
ctx.fill();
|
|
|
|
// Save the image
|
|
const buffer = canvas.toBuffer("image/png");
|
|
const outputPath = join(import.meta.dir, "..", "test", "data", "red-circle.png");
|
|
|
|
// Ensure the directory exists
|
|
await Bun.write(join(import.meta.dir, "..", "test", "data", ".keep"), "");
|
|
|
|
await Bun.write(outputPath, buffer);
|
|
console.log(`Generated test image at: ${outputPath}`);
|