2017 © Pedro Peláez
 

library captcha

A simple package to generate and check captchas

image

eusonlito/captcha

A simple package to generate and check captchas

  • Thursday, December 22, 2016
  • by eusonlito
  • Repository
  • 1 Watchers
  • 3 Stars
  • 2,489 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 14 Versions
  • 5 % Grown

The README.md

Easy Captcha :)

Build Status Latest Stable Version Total Downloads License, (*1)

A new simple and easy-to-implement captcha package., (*2)

Installation with Composer

{
    "require": {
        "eusonlito/captcha": "1.0.*"
    }
}

Demos

Default Captcha Only one font Large Captcha Short Captcha With Background Custom Letters With Noise Only Noise Points Only Noise Lines, (*3)

Usage

Template





... or ... = Captcha::img($LETTERS_COUNT, $WIDTH, $HEIGHT); ?> ... or ... = Captcha::img($LETTERS_COUNT, $WIDTH, $HEIGHT, array('class' => 'img-responsive')); ?> ... or ... = Captcha::img($LETTERS_COUNT, $WIDTH, $HEIGHT); ?> = Captcha::input(array('class' => 'form-control')); ?> ... or ... = Captcha::img(array($LETTERS_MIN, $LETTERS_MAX), $WIDTH, $HEIGHT); ?> = Captcha::input(array('class' => 'form-control')); ?>

If you are using an environment without sessions, you must add Captcha::sessionStart() before any html output (Controller)., (*4)

Checking

<?php
use Eusonlito\Captcha\Captcha;

function validate()
{
    if (!Captcha::check()) {
        throw new Exception('Captcha text is not correct');
    }
}

That's all!, (*5)

Laravel Usage

<?php
# config/app.php

return [
    ...

    'aliases' => [
        ...

        'Captcha' => 'Eusonlito\Captcha\Captcha',

        ...
    ]
];

Now you will have a Captcha class available on your controllers and views., (*6)

<?php
use Eusonlito\Captcha\Captcha;

# Simple usage with fixed word length
Captcha::source($LETTERS_COUNT, $WIDTH, $HEIGHT); # Print base64 source image code

# Define min and max word length
Captcha::source(array($LETTERS_MIN, $LETTERS_MAX), $WIDTH, $HEIGHT); # Print base64 source image code

# Same using img tag
Captcha::img($LETTERS_COUNT, $WIDTH, $HEIGHT); # Print img tag
Captcha::img(array($LETTERS_MIN, $LETTERS_MAX), $WIDTH, $HEIGHT); # Print img tag

# Img tag with parameters
Captcha::img($LETTERS_COUNT, $WIDTH, $HEIGHT, array('class' => 'img-responsive')); # Print img tag with class attribute

# Simple input tag print
Captcha::input(); # Print input tag

# Input tag with parameters
Captcha::input(array('class' => 'form-control')); # Print input tag with class attribute

Custom Setup

All custom settings will be defined before img, source or check methods calls., (*7)

<?php
use Eusonlito\Captcha\Captcha;

# Define a unique font to use (only .ttf)
Captcha::setFont(__DIR__.'/../fonts/couture-bold.ttf'); # string or array

# Add fonts to repository (only .ttf)
Captcha::addFont(array(
    __DIR__.'/../fonts/couture-bold.ttf',
    __DIR__.'/../fonts/brush-lettering-one.ttf'
));

# Set custom rgb background. Default is 255, 255, 255
Captcha::setBackground([120, 120, 120]);

# Set custom hex background.
Captcha::setBackground('#FFF000');

# Set transparent background.
Captcha::setBackground('transparent');

# Set custom rgb font color. Default is 115, 115, 115
Captcha::setColor([50, 50, 50]);

# Set custom hex color.
Captcha::setColor('#000FFF');

# Set custom padding to captcha image (approximate). Default is 0.4
Captcha::setPadding(20); // Fixed value in pixels
Captcha::setPadding(0.4); // Percent value

# Set image noise. Default is without noise
Captcha::setNoise($POINTS, $LINES); // Fixed points and lines noise
Captcha::setNoise(array($POINTS_MIN, $POINTS_MAX), array($LINES_MIN, $LINES_MAX)); // Variable points and lines noise
Captcha::setNoise(null, array($LINES_MIN, $LINES_MAX)); // Avoid points noise
Captcha::setNoise(array($POINTS_MIN, $POINTS_MAX), null); // Avoid lines noise

# Set custom available letters. Default are 'ABCDEFGHJKLMNPRSTUVWXYZ'
Captcha::setLetters('ABCDE3456');

# Set custom session name captcha storage (captcha string is stored crypted). Default is 'captcha-string'
Captcha::sessionName('my-captcha');

# Enable session before use on non session environments
Captcha::sessionStart();

Enjoy!, (*8)

The Versions

22/12 2016

dev-master

9999999-dev

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

22/12 2016

dev-develop

dev-develop

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

22/12 2016

1.0.1

1.0.1.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

22/12 2016

1.0.0

1.0.0.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

22/12 2016

0.6.2

0.6.2.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

19/12 2016

0.6.1

0.6.1.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

19/12 2016

0.6

0.6.0.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

11/05 2016

0.5

0.5.0.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

12/09 2015

0.4

0.4.0.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

12/09 2015

0.3.2

0.3.2.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

12/09 2015

0.3.1

0.3.1.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

12/09 2015

0.3

0.3.0.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

12/09 2015

0.2

0.2.0.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha

12/09 2015

0.1

0.1.0.0

A simple package to generate and check captchas

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

laravel captcha