From 96722c3f2b74399d909d56c0f80cb76a5febd2a4 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 15 Oct 2021 12:39:56 +0200 Subject: [PATCH] wip #4793 @0:10 --- src/Graphics/Image.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Graphics/Image.php b/src/Graphics/Image.php index a14ef34..2550404 100644 --- a/src/Graphics/Image.php +++ b/src/Graphics/Image.php @@ -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; -- 2.39.5