--- /dev/null
+<?php
+
+namespace Cubist\Util\Animations;
+
+use Cubist\Util\Files\Files;
+
+class OAMAnimation
+{
+ public static function unzipOAM($src, $dest = null, $type = 'oam')
+ {
+ if (null === $dest) {
+ $dest = Files::tmpdir();
+ }
+
+ if ($type === 'oam' && file_exists($dest . '/config.xml')) {
+ return $dest;
+ }
+
+ Files::mkdir($dest);
+ $cmd = "unzip $src -d $dest";
+ `$cmd`;
+ return $dest;
+ }
+
+ public static function getOAMData($src)
+ {
+ $unz = self::unzipOAM($src);
+ $config = $unz . 'config.xml';
+ if (!file_exists($config)) {
+ return null;
+ }
+
+ $x = simplexml_load_string(file_get_contents($config));
+ $config = (string)$x->oamfile['src'];
+ $config = $unz . '/' . $config;
+ $x = simplexml_load_string(file_get_contents($config), 'SimpleXMLElement', LIBXML_NOCDATA);
+ $c = Xml::toObject($x);
+
+ $props = array('default-width' => 'width', 'default-height' => 'height', 'html-page' => 'html');
+
+ $res = [];
+ foreach ($c->properties->property as $p) {
+ if (isset($props[$p->_name])) {
+ $res[$props[$p->_name]] = $p->_defaultValue;
+ }
+ }
+ preg_match('|/oam/([0-9a-z]+)/$|', $unz, $m);
+ $res['hash'] = $m[1];
+ $res['url'] = '/files/oam/' . $res['hash'] . '/Assets/' . $res['html'];
+ return $res;
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+namespace Cubist\Util\Animations;
+
+class ZipAnimation extends OAMAnimation
+{
+ public static function getZIPData($src)
+ {
+ $unz = self::unzipOAM($src,null, 'zip');
+ $index = $unz . '/index.html';
+ if (file_exists($index)) {
+ $c = file_get_contents($index);
+ 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'];
+
+ }
+ preg_match('|/zip/([0-9a-z]+)/$|', $unz, $m);
+ $res['hash'] = $m[1];
+ $res['url'] = '/files/zip/' . $res['hash'] . '/index.html';
+ return $res;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+namespace Cubist\Util\Graphics;
+
+use Cubist\Util\Animations\OAMAnimation;
+use Cubist\Util\Animations\ZipAnimation;
+use Cubist\Util\Files\Files;
+
+class Image
+{
+ protected static $_imagesizeCache = [];
+
+ public static function getimagesize($path)
+ {
+ if (isset(self::$_imagesizeCache[$path])) {
+ return self::$_imagesizeCache[$path];
+ }
+
+ $ext = Files::getExtension($path);
+ if ($ext === 'svg') {
+ $svg = simplexml_load_string(file_get_contents($path));
+ $attr = $svg->attributes();
+ if (!isset($attr['width']) || !isset($attr['height'])) {
+ $viewbox = trim($attr['viewBox']);
+ $e = explode(' ', $viewbox);
+ $width = (float)$e[2];
+ $height = (float)$e[3];
+ } else {
+ $width = (float)$attr['width'];
+ $height = (float)$attr['height'];
+ }
+ $res = array(
+ $width,
+ $height
+ );
+ } else if ($ext === 'oam') {
+ $oam = OAMAnimation::getOAMData($path);
+ $res = [$oam['width'], $oam['height']];
+ } else if ($ext === 'zip') {
+ $zip = ZipAnimation::getZIPData($path);
+ $res = [$zip['width'], $zip['height']];
+ } else {
+ $res = getimagesize($path);
+ }
+ if (!is_array($res)) {
+ $res = false;
+ } else {
+ $res = array_slice($res, 0, 2, true);
+ }
+ self::$_imagesizeCache[$path] = $res;
+ return $res;
+ }
+}
\ No newline at end of file