PHP code example of phpcfdi / image-captcha-resolver-boxfactura-ai

1. Go to this page and download the library: Download phpcfdi/image-captcha-resolver-boxfactura-ai 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/ */

    

phpcfdi / image-captcha-resolver-boxfactura-ai example snippets




use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\BoxFacturaAIResolver;
use PhpCfdi\ImageCaptchaResolver\CaptchaImage;
use PhpCfdi\ImageCaptchaResolver\UnableToResolveCaptchaException;

/** @var string $theImgElementSrcAtributte */
$image = CaptchaImage::newFromInlineHtml($theImgElementSrcAtributte);

// Creación del resolvedor
$configsFile = 'storage/sat-captcha-ai-model/configs.yaml';
$resolver = BoxFacturaAIResolver::createFromConfigs($configsFile);

try {
    $answer = $resolver->resolve($image);
} catch (UnableToResolveCaptchaException $exception) {
    echo "No se pudo resolver el captcha: {$exception->getMessage()}", PHP_EOL;
    return;
}

echo "Respuesta del captcha: {$answer->getValue()}", PHP_EOL;

use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\BoxFacturaAIResolver;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\ConfigsReader;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\Processor;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\Settings;

$configsFile = 'storage/sat-captcha-ai-model/configs.yaml';
$reader = new ConfigsReader();
$settings = $reader->settingsFromFile($configsFile);
$processor = Processor::createFromSettings($settings);

$image = 'storage/captcha.png';
$result = $processor->resolveImageFile($image);

use Imagine\Imagick\Imagine as ImagineImagick;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\BoxFacturaAIResolver;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\ConfigsReader;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\Processor;
use PhpCfdi\ImageCaptchaResolver\BoxFacturaAI\Settings;
use OnnxRuntime\InferenceSession;

\OnnxRuntime\FFI::$lib = '/usr/lib/x86_64-linux-gnu/libonnxruntime.so';

$configsFile = 'storage/sat-captcha-ai-model/configs.yaml';
$reader = new ConfigsReader();
$settings = $reader->settingsFromFile($configsFile);
$onnxSession = new InferenceSession($settings->onnxModel, providers: ['CUDAExecutionProvider']);
$imagineEngine = new ImagineImagick();
$processor = new Processor(
    $settings->imageWidth,
    $settings->imageHeight,
    $settings->alphabetArray,
    $onnxSession,
    $imagineEngine;
);
$resolver = new BoxFacturaAIResolver($processor);