visavi / captcha
Animated captcha generator
v3.1.0
2026-06-14 01:14 UTC
Requires
- php: >=8.0.0
- ext-gd: *
README
Examples
Default
Advanced
Mini
Methods
- getPhrase - Get phrase
- inline - Get captcha as a base64 data URI (image/gif), ready for an inline
<img src> - setWidth - Image width, px (Optional, default 150px)
- setHeight - Image height, px (Optional, default 40px)
- setTextColor - Text color (Optional)
- setBackgroundColor - Background color (Optional)
- setFont - Font path (Optional)
- setWindowWidth - Window width, px (Optional, default 75px)
- setPixelPerFrame - Window shift per frame, px (Optional, default 15px)
- setDelayBetweenFrames - Time between frames, in hundredths of a second (Optional, default 20 = 0.2s)
Code default
header('Content-Type: image/gif'); $captcha = new CaptchaBuilder(); $_SESSION['captcha'] = $captcha->getPhrase(); return $captcha->render();
Code advanced
header('Content-Type: image/gif'); $phrase = new PhraseBuilder(); $phrase = $phrase->getPhrase(5, '1234567890'); $captcha = new CaptchaBuilder($phrase); $captcha ->setWidth(150) ->setHeight(50) ->setTextColor(0, 0, 0) ->setBackgroundColor(255, 255, 255) ->setFont('/path-to-font') ->setWindowWidth(60) ->setPixelPerFrame(15) ->setDelayBetweenFrames(20); $_SESSION['captcha'] = $captcha->getPhrase(); return $captcha->render();
Code inline
No headers needed — the captcha is embedded straight into the page:
$captcha = new CaptchaBuilder(); $_SESSION['captcha'] = $captcha->getPhrase(); echo '<img src="' . $captcha->inline() . '" alt="captcha">';
Installation
composer require visavi/captcha
License
The class is open-sourced software licensed under the MIT license








