*/
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');
}
if (!in_array($ext, $allowedExtensions)) {
throw new \Exception('File ' . $path . ' is not a valid image');
}
+
+ $cacheKey = 'getimagesize_' . Files::hashFileAttributes($path);
+ if (isset(self::$_imagesizeCache[$cacheKey])) {
+ return self::$_imagesizeCache[$cacheKey];
+ }
+
+ $res = cache()->rememberForever($cacheKey, function () use ($ext, $path) {
+ return self::_getimagesize($path, $ext);
+ });
+ if (!$res) {
+ cache()->forget($cacheKey);
+ } else {
+ self::$_imagesizeCache[$cacheKey] = $res;
+ }
+ return $res;
+ }
+
+ protected static function _getimagesize($path, $ext)
+ {
+
+ $res = false;
if ($ext === 'pdf') {
$i = PDFTools::infos($path);
$res = $i['infos']['size'];
}
}
} else {
- $res = getimagesize($path);
+ for ($i = 0; $i <= 5; $i++) {
+ $res = @getimagesize($path);
+ if (!$res) {
+ continue;
+ }
+ break;
+ }
+
}
if (!is_array($res)) {
$res = false;
$res[3] = 'width="' . $res[0] . '" height="' . $res[1] . '"';
}
}
- self::$_imagesizeCache[$path] = $res;
return $res;
}
}
\ No newline at end of file