]> _ Git - cubist_util.git/commitdiff
wip #7894 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 14 Jan 2026 13:48:58 +0000 (14:48 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 14 Jan 2026 13:48:58 +0000 (14:48 +0100)
src/CommandLine/Docling.php [new file with mode: 0644]

diff --git a/src/CommandLine/Docling.php b/src/CommandLine/Docling.php
new file mode 100644 (file)
index 0000000..ddeea82
--- /dev/null
@@ -0,0 +1,31 @@
+<?php
+
+namespace Cubist\Util\CommandLine;
+
+use Cubist\Util\CommandLine;
+
+class Docling extends CommandLine
+{
+    protected $_prog = 'docling';
+
+    public function __construct($output = null, $error = true, $outputPrefix = null)
+    {
+        parent::__construct('docling', $output, $error, $outputPrefix);
+    }
+
+    public static function OCR($image, $locale = null)
+    {
+        $out = $image . '.' . md5($locale) . '.md';
+        if (!file_exists($out) || filemtime($out) < filemtime($image) || filemtime($out) < filemtime(__FILE__)) {
+            $cli = new self();
+            $cli->setArg('to', 'md');
+            if ($locale) {
+                $cli->setArg('ocr-lang', $locale);
+            }
+            $cli->setArg('output', $out);
+            $cli->setArg(null, $image);
+            $cli->execute();
+        }
+        return file_get_contents($out);
+    }
+}
\ No newline at end of file