]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Images.php
Changes:
[friendica.git] / src / Util / Images.php
index 130544130493ccdc6d4fd9a45c887127d831ad9f..e5b8afbb545cb24fda69f574468d07ffb75dda80 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2023, the Friendica project
+ * @copyright Copyright (C) 2010-2024, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -21,6 +21,7 @@
 
 namespace Friendica\Util;
 
+use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\DI;
 use Friendica\Model\Photo;
@@ -181,10 +182,11 @@ class Images
         * Gets info array from given URL, cached data has priority
         *
         * @param string $url
+        * @param bool   $ocr
         * @return array Info
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function getInfoFromURLCached(string $url): array
+       public static function getInfoFromURLCached(string $url, bool $ocr = false): array
        {
                $data = [];
 
@@ -192,12 +194,12 @@ class Images
                        return $data;
                }
 
-               $cacheKey = 'getInfoFromURL:' . sha1($url);
+               $cacheKey = 'getInfoFromURL:' . sha1($url . $ocr);
 
                $data = DI::cache()->get($cacheKey);
 
                if (empty($data) || !is_array($data)) {
-                       $data = self::getInfoFromURL($url);
+                       $data = self::getInfoFromURL($url, $ocr);
 
                        DI::cache()->set($cacheKey, $data);
                }
@@ -209,10 +211,11 @@ class Images
         * Gets info from URL uncached
         *
         * @param string $url
+        * @param bool   $ocr
         * @return array Info array
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       public static function getInfoFromURL(string $url): array
+       public static function getInfoFromURL(string $url, bool $ocr = false): array
        {
                $data = [];
 
@@ -257,6 +260,14 @@ class Images
 
                if ($image->isValid()) {
                        $data['blurhash'] = $image->getBlurHash();
+                       
+                       if ($ocr) {
+                               $media = ['img_str' => $img_str];
+                               Hook::callAll('ocr-detection', $media);
+                               if (!empty($media['description'])) {
+                                       $data['description'] = $media['description'];
+                               }
+                       }
                }
 
                $data['size'] = $filesize;