<?php
$imageFolder = __DIR__ . '/tempImage';
$textFolder = __DIR__ . '/tempText';
$tesseractPath = 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe';
$outputFileBase = 'box';
$fileCounter = 12;
foreach (glob($imageFolder . '/*.png') as $imagePath) {
$sanitizedImageName = str_replace(' ', '', $imagePath);
$outputFilePath = "$textFolder/$outputFileBase$fileCounter";
$command = "\"$tesseractPath\" \"$sanitizedImageName\" \"$outputFilePath\"";
exec($command);
echo "Tesseract command: $command\n";
$outputFile = $outputFileBase . $fileCounter . '.txt';
if (file_exists($outputFilePath . '.txt')) {
$lines = file($outputFilePath . '.txt', FILE_IGNORE_NEW_LINES);
echo "Extracted Text for $imagePath:\n<br>" . implode("<br>", $lines) . "\n<br>";
echo "<br><br><br>";
$fileCounter++;
} else {
echo "Error: Output file not created for $imagePath.<br>";
}
}
echo "<br>All text extracted from images in tempImage folder.<br>";
?>