visavi/captcha

Animated captcha generator

v3.0.0 2022-03-29 20:37 UTC

This package is auto-updated.

Last update: 2024-05-29 04:42:37 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Examples

Default

example1 example2 example3

Advanced

example4 example5 example6

Mini

example7 example8 example9

Methods

  • getPhrase - Get phrase
  • 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, ms) (Optional, default 20ms)

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();

Installation

composer require visavi/captcha

License

The class is open-sourced software licensed under the MIT license