egment/captcha

A captcha package for separation web system.

v0.3.1 2020-03-27 06:05 UTC

This package is auto-updated.

Last update: 2025-03-27 17:28:34 UTC


README

Quick Start

  • The simplest way to use it
use Egment/captcha;

$path = (new captcha)->create();
//Above return value looks like this:
[
    'master_path' => 'foo.jpg',
    'part_path' => 'bar.jpg'
]

//also we can specified a type parameter to add base64 code value.
(new captcha)->store(1);
//This return value will be looks like this:
[
    'master_path' => 'foo.jpg',
    'part_path' => 'bar.jpg',
    'master_base64' => 'MASTER_WHAT_BASE64CODE_LOOKSLIKE',
    'part_base64' => 'MASTER_WHAT_BASE64CODE_LOOKSLIKE',
]
  • You can also get base64encode image without store it through this code:
    $captcha = new SlideCaptcha();
    $result = $captcha->get();

Above code will only return base64code: [ 'master_base64' => 'MASTER_WHAT_BASE64CODE_LOOKSLIKE', 'part_base64' => 'MASTER_WHAT_BASE64CODE_LOOKSLIKE', ]

  • Use configure options
use Egment/captcha
$options = [
    'store_path' => './', //captcha image store path
    'bg_path' => './',	//background pictures that egment/captcha will use
    'master_name' => 'foo' . time(),
    'part_name' => 'bar' . time(),
    'part_size' => 30, //part captcha size
    'bg_exts' => ['jpg','jpeg','png'] //allowed background pictures extensions
    
]
$captcha = new Capthca($options)
$result = $captcha->create();
  • Use auth method to authenticate input parameters.
$captcha->auth($positionParameters, function ($params, $instance) {
    return $instance->authSlidePosition($params['position'], $instance->getPartMiddlePoint()[0]);
});
  • Use getPartPoints method to get part points
 $arr = $captcha->getPartPoints()
  • Use getWidth and getHeight to get part properties
 $width = $captcha->getPartWidth()
 $height = $captcha->getPartHeight()