]> _ Git - cubist_util.git/commitdiff
wip #6611 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 5 Jan 2024 14:53:28 +0000 (15:53 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 5 Jan 2024 14:53:28 +0000 (15:53 +0100)
src/Graphics/Image.php
src/Graphics/Lottie.php [new file with mode: 0644]

index 4d787ddc9b81e1c7124e66bbb405227235d08c62..3f326c2c98b9473e4464866339573353d4cde2e9 100644 (file)
@@ -90,12 +90,9 @@ class Image
                 $res = [$zip['width'], $zip['height']];
             }
         } else if ($ext === 'html') {
-            $htmlContent = Text::normalizeLines(file_get_contents($path));
-            if (stristr($htmlContent, '<div id="lottie"></div>')) {
-                if (preg_match('/var animationData = (\{.*\})/', $htmlContent, $m)) {
-                    $ad = json_decode(trim($m[1]), true);
-                    $res = [$ad['w'], $ad['h']];
-                }
+            $lottie = Lottie::getAnimationDataFromHTMLFile($path);
+            if ($lottie) {
+                $res = [$lottie['w'], $lottie['h']];
             }
         } else {
             for ($i = 0; $i <= 5; $i++) {
diff --git a/src/Graphics/Lottie.php b/src/Graphics/Lottie.php
new file mode 100644 (file)
index 0000000..2451829
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+namespace Cubist\Util\Graphics;
+
+use Cubist\Util\Text;
+
+class Lottie
+{
+    protected static function getFileContents($path)
+    {
+        return Text::normalizeLines(file_get_contents($path));
+    }
+
+    /**
+     * @param $path
+     * @return false|array
+     */
+    public static function getAnimationDataFromHTMLFile($path){
+        $htmlContent = Text::normalizeLines(file_get_contents($path));
+        if (stristr($htmlContent, '<div id="lottie"></div>')) {
+            if (preg_match('/var animationData = (\{.*\})/', $htmlContent, $m)) {
+                return json_decode(trim($m[1]), true);
+            }
+        }
+        return false;
+    }
+
+}
\ No newline at end of file