]> git.mxchange.org Git - friendica.git/commitdiff
Detect the mimetype for external resources
authorMichael <heluecht@pirati.ca>
Wed, 30 Jun 2021 03:47:53 +0000 (03:47 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 30 Jun 2021 03:47:53 +0000 (03:47 +0000)
src/Module/Photo.php

index 84c2c7fce3dfdc8d1b9267cf6301dd4526b4445d..d6f58e610f882d3c988936d84de81f274118a971 100644 (file)
@@ -28,8 +28,10 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Photo as MPhoto;
 use Friendica\Model\Post;
+use Friendica\Model\Storage\ExternalResource;
 use Friendica\Util\Proxy;
 use Friendica\Object\Image;
+use Friendica\Util\Images;
 
 /**
  * Photo Module
@@ -99,6 +101,15 @@ class Photo extends BaseModule
 
                $stamp = microtime(true);
                $imgdata = MPhoto::getImageDataForPhoto($photo);
+
+               // The mimetype for an external resources can only be known after it had been fetched
+               if ($photo['backend-class'] == ExternalResource::NAME) {
+                       $mimetype = Images::getMimeTypeByData($imgdata);
+                       if (!empty($mimetype)) {
+                               $photo['type'] = $mimetype;
+                       }
+               }
+
                $data = microtime(true) - $stamp;
 
                if (empty($imgdata)) {