]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Images.php
spelling: calendar
[friendica.git] / src / Util / Images.php
index c36ce26899886c446857d70df7c86c37433ae54b..90d120081b66527e5682f2860e8b94dec5c7766a 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2022, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -25,6 +25,7 @@ use Friendica\Core\Logger;
 use Friendica\DI;
 use Friendica\Model\Photo;
 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
+use Friendica\Object\Image;
 
 /**
  * Image utilities
@@ -179,7 +180,7 @@ class Images
        /**
         * Gets info array from given URL, cached data has priority
         *
-        * @param string $url URL
+        * @param string $url
         * @return array Info
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
@@ -207,7 +208,7 @@ class Images
        /**
         * Gets info from URL uncached
         *
-        * @param string $url URL
+        * @param string $url
         * @return array Info array
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
@@ -228,7 +229,12 @@ class Images
                }
 
                if (empty($img_str)) {
-                       $img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4);
+                       try {
+                               $img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4);
+                       } catch (\Exception $exception) {
+                               Logger::notice('Image is invalid', ['url' => $url, 'exception' => $exception]);
+                               return [];
+                       }
                }
 
                if (!$img_str) {
@@ -244,10 +250,16 @@ class Images
                }
 
                if ($data) {
+                       $image = new Image($img_str);
+
+                       if ($image->isValid()) {
+                               $data['blurhash'] = $image->getBlurHash();
+                       }
+
                        $data['size'] = $filesize;
                }
 
-               return $data ?? [];
+               return is_array($data) ? $data : [];
        }
 
        /**