]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Images.php
Standards
[friendica.git] / src / Util / Images.php
index 3b07aee2fca1399e35bc6a994ed3459d70b2ce46..077509d3cb5e6e1c64105e2a7886bd131cf31be5 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -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
         *
@@ -185,14 +209,15 @@ class Images
                }
 
                if (Network::isLocalLink($url) && ($data = Photo::getResourceData($url))) {
-                       $photo = Photo::getPhoto($data['guid'], $data['scale']);
+                       $photo = Photo::selectFirst([], ['resource-id' => $data['guid'], 'scale' => $data['scale']]);
                        if (!empty($photo)) {
                                $img_str = Photo::getImageDataForPhoto($photo);
                        }
+                       // @todo Possibly add a check for locally stored files
                }
 
                if (empty($img_str)) {
-                       $img_str = DI::httpRequest()->fetch($url, 4);
+                       $img_str = DI::httpClient()->fetch($url, 4);
                }
 
                if (!$img_str) {