PHP code example of egment / captcha

1. Go to this page and download the library: Download egment/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/ */

    

egment / captcha example snippets


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',
]

    $captcha = new SlideCaptcha();
    $result = $captcha->get();

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


$captcha->auth($positionParameters, function ($params, $instance) {
    return $instance->authSlidePosition($params['position'], $instance->getPartMiddlePoint()[0]);
});

 $arr = $captcha->getPartPoints()

 $width = $captcha->getPartWidth()
 $height = $captcha->getPartHeight()