visavi/captcha

动画验证码生成器

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

This package is auto-updated.

Last update: 2024-08-29 05:30:43 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

示例

默认

example1 example2 example3

高级

example4 example5 example6

迷你

example7 example8 example9

方法

  • getPhrase - 获取短语
  • setWidth - 图像宽度,像素(可选,默认150像素)
  • setHeight - 图像高度,像素(可选,默认40像素)
  • setTextColor - 文本颜色(可选)
  • setBackgroundColor - 背景颜色(可选)
  • setFont - 字体路径(可选)
  • setWindowWidth - 窗口宽度,像素(可选,默认75像素)
  • setPixelPerFrame - 每帧窗口移动,像素(可选,默认15像素)
  • setDelayBetweenFrames - 两帧之间时间,毫秒(可选,默认20毫秒)

默认代码

header('Content-Type: image/gif');

$captcha = new CaptchaBuilder();
$_SESSION['captcha'] = $captcha->getPhrase();

return $captcha->render();

高级代码

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

安装

composer require visavi/captcha

许可证

该类是开源软件,许可协议为 MIT 许可协议