]> _ Git - fluidbook_tools.git/commitdiff
wait #6273 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 13 Sep 2023 17:06:54 +0000 (19:06 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 13 Sep 2023 17:06:54 +0000 (19:06 +0200)
src/Links/Link.php

index 940efd8c2f9a06734c3e4291b12f606ba2121d08..6d1ba211d47b1872d90b19e100cec62243f688bf 100644 (file)
@@ -14,6 +14,7 @@ use Cubist\Util\Text;
 use Cubist\Util\Xml;
 use Fluidbook\Tools\Compiler\CompilerInterface;
 use Illuminate\Support\Facades\Cache;
+use Illuminate\Support\Facades\Log;
 use SodiumException;
 use stdClass;
 
@@ -914,32 +915,40 @@ class Link
     public static function scanQRCode($link, $compiler)
     {
 
-        $image = ZoomLink::generateImage([
-            'id' => $link['uid'],
-            'page' => $link['page'],
-            'maxzoom' => 8,
-            'group' => '',
-            'group-count' => 0,
-            'width' => round($link['width']),
-            'height' => round($link['height']),
-            'x' => round($link['left']),
-            'y' => round($link['top']),
-            'border' => 0,
-            'borderColor' => '',
-        ], $compiler, 'qrcodereader', 'qrcode', false, false);
+        $zooms = [1, 2, 4, 8, 16];
 
+        foreach ($zooms as $zoom) {
+            $image = ZoomLink::generateImage([
+                'id' => $link['uid'],
+                'page' => $link['page'],
+                'maxzoom' => $zoom,
+                'group' => '',
+                'group-count' => 0,
+                'width' => round($link['width']),
+                'height' => round($link['height']),
+                'x' => round($link['left']),
+                'y' => round($link['top']),
+                'border' => 0,
+                'borderColor' => '',
+            ], $compiler, 'qrcodereader', 'qrcode', false, false);
 
-        return Cache::rememberForever('qrcode_' . hash('sha256', $image), function () use ($image) {
-            try {
-                $result = (new QRCode)->readFromFile($image);
-                return (string)$result;
-            } catch (\Exception $e) {
 
+            $res = Cache::rememberForever('qrcode_' . hash('sha256', $image), function () use ($image) {
+                try {
+                    $result = (new QRCode)->readFromFile($image);
+                    $stringRes = (string)$result;
+                    return $stringRes;
+                } catch (\Exception $e) {
+
+                }
+                return '';
+            });
+            if ($res) {
+                return $res;
             }
-            return '';
-        });
+        }
 
+        Log::warning('QRcode not found ' . $link['uid']);
+        return '';
     }
-
-
 }