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 buffer and solution text
import { createCaptchaSync } from 'captcha-canvas';
import fs from 'fs';
const { image, text } = createCaptchaSync(300, 100);
fs.writeFileSync('captcha.png', image);
console.log('Solution:', text);
const { image, text } = createCaptchaSync(400, 150, {
captcha: {
text: 'VERIFY',
size: 55,
rotate: 20,
colors: ['#e74c3c', '#f39c12']
},
trace: { size: 3, opacity: 0.7 },
decoy: { total: 30, opacity: 0.25 }
});
import { resolveImage } from 'captcha-canvas';
// Pre-load background image
const background = await resolveImage('./texture.png');
// Generate synchronously
const { image, text } = createCaptchaSync(300, 100, {
background,
captcha: { characters: 6, opacity: 0.85 }
});
Creates a CAPTCHA image synchronously without async/await requirements.
This function provides the same functionality as
createCaptcha()
but operates synchronously, making it suitable for use cases where async operations are not desired or possible. Note that background images must be pre-loaded usingresolveImage()
.