]> _ Git - cubist_util.git/commitdiff
wait #6097 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 30 Jun 2023 09:27:38 +0000 (11:27 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 30 Jun 2023 09:27:38 +0000 (11:27 +0200)
src/Animations/ZipAnimation.php

index 7fc15e98d25a1463aa393259b0cbea922aa3796b..5e278320aa0ec304edd470dfa6d50cfc91ba08f5 100644 (file)
@@ -2,6 +2,10 @@
 
 namespace Cubist\Util\Animations;
 
+use DOMDocument;
+use DOMElement;
+use DOMXPath;
+
 class ZipAnimation extends OAMAnimation
 {
     public static function getZIPData($src)
@@ -10,12 +14,32 @@ class ZipAnimation extends OAMAnimation
         $index = $unz . '/index.html';
         if (file_exists($index)) {
             $c = file_get_contents($index);
+            $res['html'] = $c;
             if (stripos($c, '<div id="lottie"></div>') !== false) {
                 preg_match('/var animationData = (\{.*\})/', $c, $m);
                 $ad = json_decode(trim($m[1]), true);
                 $res['width'] = $ad['w'];
                 $res['height'] = $ad['h'];
+            } else {
+                $doc = new DOMDocument();
+                @$doc->loadHTML($c);
+                $xpath = new DOMXPath($doc);
+                $c = $xpath->query("//canvas");
+                foreach ($c as $canvas) {
+                    /* @var $canvas DOMElement */
+                    $res['width'] = intval((string)$canvas->getAttribute('width'));
+                    $res['height'] = intval((string)$canvas->getAttribute('height'));
+                }
+
+                $m = $xpath->query('//meta[@name="width"]');
+                foreach ($m as $meta) {
+                    $res['width'] = intval((string)$meta->getAttribute('content'));
+                }
 
+                $m = $xpath->query('//meta[@name="height"]');
+                foreach ($m as $meta) {
+                    $res['height'] = intval((string)$meta->getAttribute('content'));
+                }
             }
             $res['path'] = $unz;
             return $res;