]> _ Git - cubist_util.git/commitdiff
wip #4793 @0:10
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 15 Oct 2021 10:39:56 +0000 (12:39 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 15 Oct 2021 10:39:56 +0000 (12:39 +0200)
src/Graphics/Image.php

index a14ef3470a54b2b76e79fba95788f92689a8ff72..25504049971344d2dd09c02fb5e017b97557f24c 100644 (file)
@@ -10,13 +10,25 @@ class Image
 {
     protected static $_imagesizeCache = [];
 
+    /**
+     * @throws \Exception
+     */
     public static function getimagesize($path)
     {
         if (isset(self::$_imagesizeCache[$path])) {
             return self::$_imagesizeCache[$path];
         }
 
+        if (!file_exists($path)) {
+            throw new \Exception('File ' . $path . ' does not exist');
+        }
+
+        $allowedExtensions = ['svg', 'oam', 'zip', 'jpeg', 'jpg', 'gif', 'png', 'webm'];
+
         $ext = Files::getExtension($path);
+        if (!in_array($ext, $allowedExtensions)) {
+            throw new \Exception('File ' . $path . ' is not a valid image');
+        }
         if ($ext === 'svg') {
             $svg = simplexml_load_string(file_get_contents($path));
             $attr = $svg->attributes();
@@ -45,7 +57,12 @@ class Image
         if (!is_array($res)) {
             $res = false;
         } else {
-            $res = array_slice($res, 0, 2, true);
+            if (!isset($res[2])) {
+                $res[2] = 0;
+            }
+            if (!isset($res[3])) {
+                $res[3] = 'width="' . $res[0] . '" height="' . $res[1] . '"';
+            }
         }
         self::$_imagesizeCache[$path] = $res;
         return $res;