[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [FIX] Enhance executable detection in ocrLib for cross-platform compatibility
"SoftStart Code \(@softstartcode\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6928e08cc5b8_29d706504657df@gitlab-sidekiq-low-urgency-cpu-bound-v2-5df5c99858-btvth.mail> |
SoftStart Code pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki Commits: 4e08e9dc by Sandeep D at 2025-11-27T23:30:23+00:00 [FIX] Enhance executable detection in ocrLib for cross-platform compatibility --- * [FIX] Enhance executable detection in ocrLib for cross-platform compatibility (cherry picked from commit aa479b0d982a75ca2dc36f5bb4144a247d6e03cf) Co-authored-by: sandy-12 <sandeep.anandbhai-NHSG37FGo5wS/6/[email protected]> See merge request tikiwiki/tiki!9083 - - - - - 2 changed files: - lib/ocrlib.php - lib/prefs/ocr.php Changes: ===================================== lib/ocrlib.php ===================================== @@ -8,6 +8,7 @@ use thiagoalessio\TesseractOCR\TesseractOCR; use thiagoalessio\TesseractOCR\FriendlyErrors; use Tiki\Lib\Alchemy; use Symfony\Component\Filesystem\Filesystem; +use Tiki\TikiInit; /** * @@ -84,17 +85,26 @@ class ocrLib extends TikiLib } $executable = escapeshellarg($executable); - $possibleCommands = [ - 'type -p ' . $executable . ' 2>&1', - 'where ' . $executable . ' 2>&1', - 'which ' . $executable . ' 2>&1' - ]; + if (TikiInit::isWindows()) { + $possibleCommands = [ + 'where ' . $executable . ' 2>&1' + ]; + } else { + $possibleCommands = [ + 'command -v ' . $executable . ' 2>/dev/null', + 'which ' . $executable . ' 2>/dev/null' + ]; + } + foreach ($possibleCommands as $cmd) { $output = []; $return = 0; exec($cmd, $output, $return); if ($return === 0) { - return array_shift($output); + $result = trim(array_shift($output)); + if (! empty($result)) { + return $result; + } } } @@ -285,6 +295,16 @@ class ocrLib extends TikiLib $tesseract = new TesseractOCR($fileName); if (! empty($prefs['ocr_tesseract_path']) && file_exists($prefs['ocr_tesseract_path'])) { $tesseract->executable($prefs['ocr_tesseract_path']); + } else { + try { + $autoExecutable = $this->whereIsExecutable('tesseract'); + } catch (Exception $e) { + $autoExecutable = null; + } + + if (! empty($autoExecutable) && file_exists($autoExecutable)) { + $tesseract->executable($autoExecutable); + } } return $tesseract; } ===================================== lib/prefs/ocr.php ===================================== @@ -16,9 +16,13 @@ function prefs_ocr_list() try { $tesseractPath = $ocr->whereIsExecutable('tesseract') ?: 'tesseract'; - $pdfimagesPath = $ocr->whereIsExecutable('pdfimages') ?: 'pdfimages'; } catch (Exception $e) { $tesseractPath = 'tesseract'; + } + + try { + $pdfimagesPath = $ocr->whereIsExecutable('pdfimages') ?: 'pdfimages'; + } catch (Exception $e) { $pdfimagesPath = 'pdfimages'; } View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/4e08e9dc402aceb712a8f3388a956c0ed126c4ee -- View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/4e08e9dc402aceb712a8f3388a956c0ed126c4ee You're receiving this email because of your account on gitlab.com. _______________________________________________ TikiWiki-cvs mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs