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
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];