[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Enhance executable detection in ocrLib for cross-platform compatibility
"Sandeep D \(@sandy-12\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <69204563d043b_2a17ee2c641e2@gitlab-sidekiq-low-urgency-cpu-bound-v2-5c974d7c55-kxnkh.mail> |
Sandeep D pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
cb3a138d by Sandeep D at 2025-11-21T10:48:41+00:00
[FIX] Enhance executable detection in ocrLib for cross-platform compatibility
---
* [FIX] Enhance executable detection in ocrLib for cross-platform compatibility
See merge request tikiwiki/tiki!9082
- - - - -
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/cb3a138daf0d17110a2dc16615e638018c8cedfa
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/cb3a138daf0d17110a2dc16615e638018c8cedfa
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