MTGRandom/install/testocr.php

33 lines
591 B
PHP

<?php
if ( php_sapi_name() != "cli" ) exit();
require_once 'vendor/autoload.php';
use thiagoalessio\TesseractOCR\TesseractOCR;
if ( $argc != 2 ) {
echo "Must specify image file on command line\n";
echo "\n";
exit();
}
$imagefile = $argv[1];
if ( !file_exists($imagefile) ) {
echo "Error: could not find file \"{$imagefile}\"\n";
echo "\n";
exit();
}
try {
$text = (new TesseractOCR($imagefile))
->lang('eng') // Set languages
->run();
echo $text;
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage(), "\n";
}
// vim: ts=4 sw=4: