From: Vincent Vanwaelscappel Date: Tue, 30 Jul 2024 12:42:28 +0000 (+0200) Subject: wip #7026 @0:10 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2aec132b49e4fd3905249cf25fa62f9c48624e2a;p=cubist_util.git wip #7026 @0:10 --- diff --git a/src/Graphics/Image.php b/src/Graphics/Image.php index 3f326c2..f514ae7 100644 --- a/src/Graphics/Image.php +++ b/src/Graphics/Image.php @@ -12,6 +12,13 @@ use Illuminate\Support\Facades\Log; class Image { protected static $_imagesizeCache = []; + protected static $_extensions = ['svg', 'oam', 'zip', 'jpeg', 'jpg', 'gif', 'png', 'webm', 'pdf', 'html']; + + public static function isValidImage($path) + { + + return in_array(Files::getExtension($path), self::$_extensions); + } /** * @throws \Exception @@ -21,14 +28,12 @@ class Image if (!file_exists($path)) { throw new \Exception('File ' . $path . ' does not exist'); } - - $allowedExtensions = ['svg', 'oam', 'zip', 'jpeg', 'jpg', 'gif', 'png', 'webm', 'pdf', 'html']; - - $ext = Files::getExtension($path); - if (!in_array($ext, $allowedExtensions)) { + if (!self::isValidImage($path)) { throw new \Exception('File ' . $path . ' is not a valid image'); } + $ext = Files::getExtension($path); + $cacheKey = 'getimagesize_' . Files::hashFileAttributes($path); if (isset(self::$_imagesizeCache[$cacheKey])) { return self::$_imagesizeCache[$cacheKey];