PHPackages                             ixianming/image-captcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ixianming/image-captcha

ActiveLibrary

ixianming/image-captcha
=======================

Image Captcha. The captcha font can be automatically adapted to the image size. Based on the `intervention/image` library, the installation and use conditions are the same as for `intervention/image`. Please read README.MD for more details.

1.0.0(6y ago)31971MITPHP

Since Apr 27Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ixianming/image-captcha)[ Packagist](https://packagist.org/packages/ixianming/image-captcha)[ Docs](https://github.com/ixianming/image-captcha)[ RSS](/packages/ixianming-image-captcha/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Image Captcha
=============

[](#image-captcha)

\[TOC\]

关于扩展包
-----

[](#关于扩展包)

- 本扩展包基于 `intervention/image` 库。安装、使用条件与 `intervention/image` 库相同。

    `intervention/image` 库默认使用 `gd` 驱动来创建图片，如需更改驱动，修改 `intervention/image` 的配置文件既可。

    `intervention/image` 库：

    官网：

    GitHUb：
- **本扩展包使用的字体为：站酷文艺体。**

    **商业使用时，请确认您有此字体的使用权限。**

    **或者，你也可以在扩展包的配置文件中将字体替换为有使用权限的字体。**

    > 注：站酷文艺体的使用范围：免费授权全社会使用（包括商用）。详见官网：

安装
--

[](#安装)

### 安装条件

[](#安装条件)

**无论是否在框架中使用，只要能使用 `intervention/image` 库的地方，均可安装使用本扩展包。**

- `intervention/image` &gt;= 2

### 使用 Composer 安装

[](#使用-composer-安装)

```
composer require ixianming/image-captcha
```

使用
--

[](#使用)

### 配置文件

[](#配置文件)

配置文件 `image_captcha.php` 存放在扩展包的 `config` 目录下。您可在配置文件中自定义图片验证码的设置。

如果你希望自定义验证码设置，且 `composer update` 时，自定义配置不受影响，请在自定义配置后及时备份，否则，当扩展包更新时，你的自定义配置就会被覆盖。

### 引用扩展包

[](#引用扩展包)

```
use Ixianming\ImageCaptcha\Captcha;
```

### 创建验证码实例

[](#创建验证码实例)

```
$captcha = new Captcha();
```

如果你需要使用自定义配置，在配置文件中定义自定义配置后，创建实例时，传入自定义配置的名称既可。

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

### 获取验证码字符串

[](#获取验证码字符串)

一个实例无论调用 `code` 方法几次，返回的验证码都是一致的，直至销毁此验证码。

```
$code = $captcha->code();
```

### 获取验证码图片的 Base64 编码

[](#获取验证码图片的-base64-编码)

```
$base64 = $captcha->base64();

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

### 获取验证码图片的编码数据

[](#获取验证码图片的编码数据)

`$imgType` 参数表示图片格式，支持的图片格式与 `intervention/image` 库的 `encode` 方法支持的格式一致。默认返回 `base64` 编码数据。

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

### 响应验证码图片

[](#响应验证码图片)

`$imgType` 参数表示图片格式，支持的图片格式与 `intervention/image` 库的 `response` 方法支持的格式一致。默认响应为 `jpg` 格式。

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

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

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

许可证
---

[](#许可证)

本扩展包基于 [MIT license](https://opensource.org/licenses/MIT) 开源。

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2212d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d1b64fb0c76f2ab3ea6ea83898d36ef4d3c62e99a9983a9d145b3b5a9a79c118?d=identicon)[ixianming](/maintainers/ixianming)

---

Top Contributors

[![ixianming](https://avatars.githubusercontent.com/u/15683919?v=4)](https://github.com/ixianming "ixianming (1 commits)")

---

Tags

captchaimage captchaimage verification code

### Embed Badge

![Health badge](/badges/ixianming-image-captcha/health.svg)

```
[![Health](https://phpackages.com/badges/ixianming-image-captcha/health.svg)](https://phpackages.com/packages/ixianming-image-captcha)
```

###  Alternatives

[mews/captcha

Laravel 5/6/7/8/9/10/11/12 Captcha Package

2.6k5.5M84](/packages/mews-captcha)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
