[TikiWiki-commits] [Git][tikiwiki/tiki][29.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 <6928e0d031d2d_2aea7dec071265@gitlab-sidekiq-low-urgency-cpu-bound-v2-5df5c99858-x7p9n.mail>

SoftStart Code pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki


Commits:
156ca1b6 by Sandeep D at 2025-11-27T23:29:59+00:00
[FIX] Enhance executable detection in ocrLib for cross-platform compatibility
---
* [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


(cherry picked from commit cb3a138daf0d17110a2dc16615e638018c8cedfa)

Co-authored-by: Sandeep D <sandeep.anandbhai-NHSG37FGo5wS/6/[email protected]>

See merge request tikiwiki/tiki!9085

- - - - -


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/156ca1b6282cf39193074d5d59673f41b1311e9d

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/156ca1b6282cf39193074d5d59673f41b1311e9d
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.