]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Images.php
Merge pull request #10967 from annando/api
[friendica.git] / src / Util / Images.php
index a65f9a1a8b16fa24ed022a74ea1711d4aee0730a..8a810510f0489916363b98e1d397e430b602a9e0 100644 (file)
@@ -22,8 +22,8 @@
 namespace Friendica\Util;
 
 use Friendica\Core\Logger;
-use Friendica\Core\System;
 use Friendica\DI;
+use Friendica\Model\Photo;
 
 /**
  * Image utilities
@@ -184,7 +184,17 @@ class Images
                        return $data;
                }
 
-               $img_str = DI::httpRequest()->fetch($url, 4);
+               if (Network::isLocalLink($url) && ($data = Photo::getResourceData($url))) {
+                       $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::httpClient()->fetch($url, 4);
+               }
 
                if (!$img_str) {
                        return [];
@@ -193,18 +203,7 @@ class Images
                $filesize = strlen($img_str);
 
                try {
-                       if (function_exists("getimagesizefromstring")) {
-                               $data = @getimagesizefromstring($img_str);
-                       } else {
-                               $tempfile = tempnam(get_temppath(), "cache");
-
-                               $stamp1 = microtime(true);
-                               file_put_contents($tempfile, $img_str);
-                               DI::profiler()->saveTimestamp($stamp1, "file");
-
-                               $data = getimagesize($tempfile);
-                               unlink($tempfile);
-                       }
+                       $data = @getimagesizefromstring($img_str);
                } catch (\Exception $e) {
                        return [];
                }