X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FImages.php;h=d7a58b52aa7faeaf3a275488412c4139405a80e8;hb=093dd70e790def206d6f7d48cfac095c29eb10a5;hp=cd4704dcee068018ec0f1a4c4b8a701930e257f6;hpb=e56a53647bd5469551bf4f9ef2df50a5dd16b943;p=friendica.git diff --git a/src/Util/Images.php b/src/Util/Images.php index cd4704dcee..d7a58b52aa 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -46,6 +46,30 @@ class Images return $m; } + /** + * Return file extension for mime type + * @param string $mimetype + * @return string + */ + public static function getExtensionByMimeType(string $mimetype): string + { + switch ($mimetype) { + case 'image/png': + $imagetype = IMAGETYPE_PNG; + break; + + case 'image/gif': + $imagetype = IMAGETYPE_GIF; + break; + + default: + $imagetype = IMAGETYPE_JPEG; + break; + } + + return image_type_to_extension($imagetype); + } + /** * Returns supported image mimetypes and corresponding file extensions * @@ -160,12 +184,14 @@ class Images return $data; } - $data = DI::cache()->get($url); + $cacheKey = 'getInfoFromURL:' . sha1($url); + + $data = DI::cache()->get($cacheKey); if (empty($data) || !is_array($data)) { $data = self::getInfoFromURL($url); - DI::cache()->set($url, $data); + DI::cache()->set($cacheKey, $data); } return $data;