generate-test-image.ts 923 B

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env node
  2. import { createCanvas } from "canvas";
  3. import { mkdirSync, writeFileSync } from "fs";
  4. import { join, dirname } from "path";
  5. import { fileURLToPath } from "url";
  6. const __filename = fileURLToPath(import.meta.url);
  7. const __dirname = dirname(__filename);
  8. // Create a 200x200 canvas
  9. const canvas = createCanvas(200, 200);
  10. const ctx = canvas.getContext("2d");
  11. // Fill background with white
  12. ctx.fillStyle = "white";
  13. ctx.fillRect(0, 0, 200, 200);
  14. // Draw a red circle in the center
  15. ctx.fillStyle = "red";
  16. ctx.beginPath();
  17. ctx.arc(100, 100, 50, 0, Math.PI * 2);
  18. ctx.fill();
  19. // Save the image
  20. const buffer = canvas.toBuffer("image/png");
  21. const outputPath = join(__dirname, "..", "test", "data", "red-circle.png");
  22. // Ensure the directory exists
  23. mkdirSync(join(__dirname, "..", "test", "data"), { recursive: true });
  24. writeFileSync(outputPath, buffer);
  25. console.log(`Generated test image at: ${outputPath}`);