crutch/captcha-generator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

crutch/captcha-generator

最新稳定版本:v1.1.0

Composer 安装命令:

composer require crutch/captcha-generator

包简介

The PHP GD captcha generator

关键字:

README 文档

README

Captcha Generator.

This code based on KCAPTCHA v2.0

example

Install

composer require crutch/captcha-generator:^1.0

Usage

<?php

use Crutch\CaptchaGenerator\CaptchaGenerator;

require __DIR__ . '/vendor/autoload.php';

$generator = (new CaptchaGenerator())
    ->withSize(250, 100) // Image size. By default, 160x80
    ->withBackgroundColor(20, 20, 20) // Set background color (r, g, b). By default, random light color
    ->withForegroundColor(200, 200, 200) // Set foreground color (r, g, b). By default, random dark color
    ->withCredits('crutch captcha') // Added text to image bottom. By default, NULL
    ->withSpaces(true) // Adds spaces between characters. By default, FALSE
    ->withFluctuationAmplitude(0) // Vertical fluctuation amplitude. By default, 8
    ->withWhiteNoiseDensity(.1) // White noise density. By default, 1 / 6
    ->withBlackNoiseDensity(.05) // White noise density. By default, 1 / 30
    ->asJpeg(90) // Use JPEG format with quality from 1 to 100
    ->asWebp(80) // Use WEBP format with quality from 1 to 100
    ->asGif() // Use GIF format
    ->asPng(8) // Use PNG format with quality from 1 to 9
;

//
$symbols = '23456789abcdegkpqsvxyz'; // alphabet without similar symbols (o=0, 1=l, i=j, t=f)

$text = '';
for ($i = 0; $i < 6; $i++) {
    $text .= substr($symbols, mt_rand(0, strlen($symbols) - 1), 1);
}

$image = $generator->generate($text); // generate PNG image

file_put_contents('/tmp/captcha.png', $image); // save to file

echo sprintf('<img src="data:image/png;base64,%s" alt="captcha"/>', base64_encode($image)); // out inline

Fonts

You may generate fonts from ttl files

./vendor/bin/crutch-captcha-generator font:convert /path/to/input-font.ttf /path/to/output-font-simple.png

or outlined font

./vendor/bin/crutch-captcha-generator font:convert /path/to/input-font.ttf /path/to/output-font-outline.png --outline

and set it to captcha

<?php

use Crutch\CaptchaGenerator\CaptchaGenerator;

require __DIR__ . '/vendor/autoload.php';

$generator = (new CaptchaGenerator())
    ->withFont('/path/to/output-font-simple.png', true) // add custom font and unset others
    ->withFont('/path/to/output-font-outline.png') // add other custom font
;

$image = $generator->generate('abc'); // generate PNG image

统计信息

  • 总下载量: 32
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-02-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固