PHPackages                             omranjamal/real-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. [Security](/categories/security)
4. /
5. omranjamal/real-captcha

ActiveLibrary[Security](/categories/security)

omranjamal/real-captcha
=======================

Advanced Captcha generation library for PHP

v1.0-patch(11y ago)282.9k8[1 issues](https://github.com/Hedronium/RealCaptcha/issues)MITPHPPHP &gt;=5.3.0

Since Jun 12Pushed 10y ago4 watchersCompare

[ Source](https://github.com/Hedronium/RealCaptcha)[ Packagist](https://packagist.org/packages/omranjamal/real-captcha)[ Docs](http://omranjamal.github.io/RealCaptcha)[ RSS](/packages/omranjamal-real-captcha/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

RealCaptcha
===========

[](#realcaptcha)

A PHP Library that uses the [PHP-GD](http://php.net/manual/en/book.image.php) Extension to generate Captchas with only PHP.
RealCaptcha is released under the [MIT License](https://github.com/omranjamal/RealCaptcha/blob/master/LICENSE.txt). Visit the project [Homepage](http://omranjamal.github.io/RealCaptcha) for more information.

**Note:** This code is still in its Beta stage so it maybe prone to many bugs...
**Note:** The Fonts included here are not created or owned by the author of the code, but none the less, their liscenses are open-source, commercial-friendly and permit redistribution, [Check them out](#fonts) yourself.

[![Example Image](examples/output/c6.jpg)](examples/output/c6.jpg)

\##Features

- Custom Fonts
- Customizable Colors
- Supports 4 different captcha text sources

    - **Input**
    - **Custom Generator Functions**
         You can define a custom function of your own that generates the text that should be in the captcha.
    - **Random Text Generator**
         Generates a random string of Letters and Numbers.
    - **Dictionary File**
         Can use any file containing space separated words as a dictionary file to choose words from.
- Captcha Image Compression
- 3 different output formats ( **jpg**, **png**, **gif** )
- Output locations

    - To Browser
    - To File
    - Return GD Resource Handle

\##Installation The simplest method is using [Composer](https://getcomposer.org). Just require it in your `composer.json` file as such:

```
{
    "require":{
        "omranjamal/real-captcha":"dev-master"
    }
}
```

To incluude it in your project, include the composer autoloader and just create new objects of the `RealCaptcha` class under the `omranjamal\RealCaptcha` namespace as such:

```
include 'vendor/autoload.php';
$captcha = new omranjamal\RealCaptcha\RealCaptcha();
```

Alternatively you could manually clone or download this reppository and directly include the Class file in and create an object of `omranjamal\RealCaptcha\RealCaptcha`

Basic Usage
-----------

[](#basic-usage)

\###Basic

```
$captcha = new omranjamal\RealCaptcha\RealCaptcha();
$captcha->generate()->output("jpg");
```

\###Configuring All three of these code output similar Captchas to the browser in JPG Format.

While Initializing

```
$realCaptcha = new omranjamal\RealCaptcha\RealCaptcha(array(
    "height" = 200,
    "width" = 500,
    "number_of_words" = 2
));

$captcha = $realCaptcha->generate();
$captcha->output("jpg");
```

The Settings you provide at Initialzation will be used everytime the `generate()` method is called.

Using the ***`set()`*** method

```
$realCaptcha = new omranjamal\RealCaptcha\RealCaptcha();

$realCaptcha->set(array(
    "height" = 200,
    "width" = 500,
    "number_of_words" = 2
));

$captcha = $realCaptcha->generate();
$captcha->output("jpg");
```

The settings you define with the `set()` method will overwrite the settings you provided at initialization and will be used every time the `generate()` method is called.

While Generating

```
$realCaptcha = new omranjamal\RealCaptcha\RealCaptcha();

$captcha = $realCaptcha->generate(array(
    "height" = 200,
    "width" = 500,
    "number_of_words" = 2
));
$captcha->output("jpg");
```

The `generate()` method will give high priority to the settings passed to it as an argument. These setting will be forgotten as soon as the captcha is finished generating.

\###Dealing with output

```
$realCaptcha = new omranjamal\RealCaptcha\RealCaptcha();
$captcha = $realCaptcha->generate();
```

The `generate()` method returns an Output object it has two methods and a buch of Properties.

\####The Methods

- `file( path, format, quality)`: Writes Captcha to a file
- `output( format, quality)`: Sets appropriate image format headers and sends the Image data to browser

\####The Properties

- `text`: Contains a string words that are present in the captcha image, seperated by spaces
- `array`: Contains an Array of the words present in the captcha image.

\####Example This example generates a captcha and stores the captcha text in a session variable so that it can be matched later and output the captcha image to browser and also daves the image to a file named `example.jpg`

```
session_start();
$realCaptcha = new omranjamal\RealCaptcha\RealCaptcha();

$captcha = $realCaptcha->generate();
$_SESSION["captcha_text"] = $captcha->text;
$captcha->output("jpg",100);
$captcha->file("example.jpg","jpg",100);
```

\###Saving Captcha to file To save captcha to file, you can use the **`file( file_path, format, quality)`** method.

```
$captcha = $realCaptcha->generate();
$captcha->file("file.jpg" ,"jpg", 90);
```

Full List of settings
---------------------

[](#full-list-of-settings)

- **height** (a positive Integer) : Height of the generated Captcha Image.
- **width** (a positive integer) : Width of the generated Captcha Image.
- **source** (realCaptcha source type constant): Where to get the captcha text from.
    - **`omranjamal\RealCaptcha\RealCaptcha::INPUT`**: Requires you to pass the captcha text while calling `generate()` method
    - **`omranjamal\RealCaptcha\RealCaptcha::RANDOM`**: Generates a random string of letters and numbers.
    - **`omranjamal\RealCaptcha\RealCaptcha::DICTIONARY`**: Selects words at random from the dictionary file.
    - **`omranjamal\RealCaptcha\RealCaptcha::uFUNCTION`**: Requires you to set a custom made function that returns the captcha text.
- **dictionary\_file** (a valid file path): Path to the dictionary File.
- **fonts\_dir** (a valid directory path): Path to the dictory containing all the fonts.
- **number\_of\_words** (a positive integer): Number of words the captcha image should contain.
- **random\_length** (a positive integer): the length of the randomly generated string.
- **background\_color** (realCaptcha variable\_grey setting constant or array)
    - **`omranjamal\RealCaptcha\RealCaptcha::GREY_VARIABLE`** : Randomly chooses a shade from white to light ash.
    - **`array( int, int, int)`** : A numerical array containing RGB values.
- **text\_color** (array): A numerical array containing RGB values.

Advanced Usage
--------------

[](#advanced-usage)

\###Setting Background and Text color

[![Colored Example](examples/output/c3.jpg)](examples/output/c3.jpg)

```
$captcha = new omranjamal\RealCaptcha\RealCaptcha(array(
    "background_color" => array(255,0,0), //Bright Red
    "text_color" => array(255,255,255) //White
));

$captcha->generate()->output("jpg");
```

\###Using direct Input Both these codes are correct but work in different ways and the settings persist for different fractions of the run cycle.

Setting at Initialization

```
$captcha = new omranjamal\RealCaptcha\RealCaptcha(array(
    "source" => realCaptcha::INPUT
));

$captcha->generate("Text")->output("jpg");
```

Setting at Generator

```
$captcha = new omranjamal\RealCaptcha\RealCaptcha();
$captcha->generate("Text", array("source" => realCaptcha::INPUT))->output("jpg");
```

It is Completely ok to pass String or an Array as input into the generator method, thus both the following teo lines of code are valid

```
$captcha->generate("Text")->output("jpg");
$captcha->generate(array("example","text"))->output("jpg");
```

\###Using Custom Text Generator Function Unlike **Direct Input** , Custom Functions cannot be set and declared at the **generator** method, custom function usage has to be declared in the initialization settings or through the `set()` method and the function has to be define through the `textFunction()` method as the first argument. All prior to calling the `generate()` method in which you intend to use the Custom function.

[![Example Function](examples/output/c7.jpg)](examples/output/c7.jpg)

\####Example

```
$captcha = new omranjamal\RealCaptcha\RealCaptcha(array(
    "source" => realCaptcha::uFUNCTION
));

$captcha->textFunction(function(){
    return array("EXAMPLE","FUNCTION");
});

$captcha->generate()->output("jpg");
```

Fonts
-----

[](#fonts)

- [swirled2](http://www.1001fonts.com/swirled-brk-font.html)
- [Seraphim Font](http://www.1001fonts.com/seraphim-font.html)
- [Potassium Scandal](http://www.1001fonts.com/potassium-scandal-font.html)
- [RattyTatty](http://www.1001fonts.com/rattytatty-font.html)
- [Quick End Jerk](http://www.fontsquirrel.com/fonts/Quick-End-Jerk)
- [Zero &amp; Zero Is](http://www.fontsquirrel.com/fonts/Zero-Zero-Is)
- [Previewance](http://www.1001fonts.com/previewance-font.html)
- [Playdough](http://www.1001fonts.com/playdough-font.html)
- [Paper Cut](http://www.1001fonts.com/paper-cut-font.html)
- [Nervous Rex](http://www.fontsquirrel.com/fonts/Nervous-Rex)
- [Lilac Malaria](http://www.fontsquirrel.com/fonts/Lilac-Malaria)
- [Eraser](http://www.fontsquirrel.com/fonts/Eraser)
- [Edo](http://www.fontsquirrel.com/fonts/Edo)
- [CarbonType](http://www.fontsquirrel.com/fonts/CarbonType)
- [Boston Traffic](http://www.fontsquirrel.com/fonts/Boston-Traffic)
- [1942 report](http://www.fontsquirrel.com/fonts/1942-report)

Liscense
--------

[](#liscense)

RealCaptcha is released under the [MIT License](LICENSE.txt). Visit the project [Homepage](http://omran-jamal.github.io/realCaptcha/) for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 91.4% 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

Every ~173 days

Total

2

Last Release

4177d ago

### Community

Maintainers

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

---

Top Contributors

[![omranjamal](https://avatars.githubusercontent.com/u/4700757?v=4)](https://github.com/omranjamal "omranjamal (32 commits)")[![NaWer](https://avatars.githubusercontent.com/u/352868?v=4)](https://github.com/NaWer "NaWer (2 commits)")[![trendfischer](https://avatars.githubusercontent.com/u/861121?v=4)](https://github.com/trendfischer "trendfischer (1 commits)")

---

Tags

securitycaptchagenerationttffonts

### Embed Badge

![Health badge](/badges/omranjamal-real-captcha/health.svg)

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

###  Alternatives

[gregwar/captcha-bundle

Captcha bundle

3524.7M32](/packages/gregwar-captcha-bundle)[s1syphos/php-simple-captcha

Simple captcha generator

2737.8k6](/packages/s1syphos-php-simple-captcha)[lorddashme/php-simple-captcha

A simple captcha package that fit to any type of web application built on php.

102.9k](/packages/lorddashme-php-simple-captcha)

PHPackages © 2026

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