Width of the CAPTCHA image in pixels
Height of the CAPTCHA image in pixels
Optional configuration for customizing CAPTCHA appearance and security
Object containing the image promise and solution text
import { createCaptcha } from 'captcha-canvas';
import fs from 'fs';
const { image, text } = createCaptcha(300, 100);
const buffer = await image;
fs.writeFileSync('captcha.png', buffer);
console.log('Solution:', text);
const { image, text } = createCaptcha(400, 150, {
captcha: {
text: 'HELLO',
size: 60,
colors: ['#e74c3c', '#3498db', '#27ae60']
}
});
const { image, text } = createCaptcha(350, 120, {
captcha: { characters: 8, size: 45 },
trace: { color: '#95a5a6', size: 4, opacity: 0.8 },
decoy: { total: 50, opacity: 0.3, size: 18 }
});
Creates a CAPTCHA image asynchronously with automatic security features.
This is the simplest way to generate a CAPTCHA with sensible defaults and automatic security features including decoy characters, trace lines, and random text generation. The function handles the complete generation process and returns both the image and solution.