import { createCanvas } from "canvas";
import fs from "fs";
import path from "path";
// Test the placeholder image generation functionality
async function testPlaceholderGeneration() {
console.log("Testing placeholder image generation...");
try {
// Test parameters
const filename = "test-placeholder.png";
const width = 400;
const height = 300;
const color = "#3498db";
const text = "Test Placeholder Image";
// Create canvas
const canvas = createCanvas(width, height);
const ctx = canvas.getContext('2d');
// Set background color
ctx.fillStyle = color;
ctx.fillRect(0, 0, width, height);
// Calculate font size based on image dimensions
const fontSize = Math.min(width, height) / 10;
ctx.font = `${fontSize}px Arial, sans-serif`;
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
// Set text color (white for blue background)
ctx.fillStyle = 'white';
// Draw text in the center
const centerX = width / 2;
const centerY = height / 2;
ctx.fillText(text, centerX, centerY);
// Add dimensions text at the bottom
const dimensionsText = `${width} × ${height}`;
const smallFontSize = Math.min(fontSize * 0.4, 24);
ctx.font = `${smallFontSize}px Arial, sans-serif`;
ctx.fillText(dimensionsText, centerX, height - smallFontSize);
// Save the image
const buffer = canvas.toBuffer('image/png');
fs.writeFileSync(filename, buffer);
console.log(`✅ Successfully generated test image: ${filename}`);
console.log(`📐 Dimensions: ${width}×${height}`);
console.log(`🎨 Background color: ${color}`);
console.log(`📝 Text: "${text}"`);
// Check if file exists
if (fs.existsSync(filename)) {
const stats = fs.statSync(filename);
console.log(`📄 File size: ${(stats.size / 1024).toFixed(2)} KB`);
console.log(`🕒 Created: ${stats.birthtime.toLocaleString()}`);
}
} catch (error) {
console.error("❌ Error generating test image:", error);
}
}
testPlaceholderGeneration();