PHP code example of ixianming / image-captcha

1. Go to this page and download the library: Download ixianming/image-captcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ixianming / image-captcha example snippets


use Ixianming\ImageCaptcha\Captcha;

$captcha = new Captcha();

$customConfigName = 'myCaptcha';
$captcha = new Captcha($customConfigName);

$code = $captcha->code();

$base64 = $captcha->base64();

//如需修改图片质量,传入 `$quality` 参数,参数范围 0 - 100,默认为 90
$quality = 75;
$base64 = $captcha->base64($quality);

$encode = $captcha->encode(); //返回图片的 base64 编码数据

//如需指定图片的格式,传入 `$imgType` 参数。
$imgType = 'png';
$encode = $captcha->encode($imgType);

//如需修改图片质量,传入 `$quality` 参数,参数范围 0 - 100,默认为 90。
$imgType = 'png';
$quality = 75;
$encode = $captcha->encode($imgType, $quality);

$captcha->destroy();

return $captcha->response(); //响应为 jpg 格式的图片

//如需指定图片的格式,传入 `$imgType` 参数。
$imgType = 'png';
return $captcha->response($imgType);

//如需修改图片质量,传入 `$quality` 参数,参数范围 0 - 100,默认为 90。
$imgType = 'png';
$quality = 75;
return $captcha->response($imgType, $quality);