]> _ Git - cubist_util.git/commitdiff
wip #7026 @0:10
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 30 Jul 2024 12:42:28 +0000 (14:42 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 30 Jul 2024 12:42:28 +0000 (14:42 +0200)
src/Graphics/Image.php

index 3f326c2c98b9473e4464866339573353d4cde2e9..f514ae7361ad3869529a2e9e063ec2185d58aee2 100644 (file)
@@ -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];