27 lines
540 B
PHP
Executable File
27 lines
540 B
PHP
Executable File
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
$image = $_POST['image'] ?? '';
|
|
$lang = $_POST['lang'] ?? 'fra+eng';
|
|
|
|
if (empty($image)) {
|
|
echo json_encode(['error' => 'Image base64 required']);
|
|
exit;
|
|
}
|
|
|
|
$tmp = '/tmp/ocr_' . uniqid() . '.png';
|
|
file_put_contents($tmp, base64_decode($image));
|
|
|
|
$output = [];
|
|
exec("tesseract '$tmp' stdout -l $lang 2>/dev/null", $output);
|
|
$text = trim(implode("\n", $output));
|
|
|
|
@unlink($tmp);
|
|
|
|
echo json_encode([
|
|
'success' => !empty($text),
|
|
'text' => $text,
|
|
'chars' => strlen($text)
|
|
]);
|
|
|