$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++) {
--- /dev/null
+<?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