]> git.mxchange.org Git - friendica.git/blobdiff - src/Util/Images.php
Friendica copyright changed from 2023 to 2034
[friendica.git] / src / Util / Images.php
index 08553a1a9c50012f7e105d1ad620f9bb63492db3..b44b1fb8f558fe0a4dbc76078dc531e4dc8a8155 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
  *
@@ -249,17 +249,19 @@ class Images
                        return [];
                }
 
-               if ($data) {
-                       $image = new Image($img_str);
+               if (!$data) {
+                       return [];
+               }
 
-                       if ($image->isValid()) {
-                               $data['blurhash'] = $image->getBlurHash();
-                       }
+               $image = new Image($img_str);
 
-                       $data['size'] = $filesize;
+               if ($image->isValid()) {
+                       $data['blurhash'] = $image->getBlurHash();
                }
 
-               return is_array($data) ? $data : [];
+               $data['size'] = $filesize;
+
+               return $data;
        }
 
        /**
@@ -318,30 +320,49 @@ class Images
        }
 
        /**
-        * Get a link to a an image link with a preview
+        * Get a BBCode tag for an local photo page URL with a preview thumbnail and an image description
         *
         * @param string $resource_id
-        * @param string $nickname
-        * @param integer $preview
-        * @param string $ext
+        * @param string $nickname The local user owner of the resource
+        * @param int    $preview Preview image size identifier, either 0, 1 or 2 in decreasing order of size
+        * @param string $ext Image file extension
         * @param string $description
         * @return string
         */
-       public static function getImageUrl(string $resource_id, string $nickname, int $preview, string $ext, string $description): string
+       public static function getBBCodeByResource(string $resource_id, string $nickname, int $preview, string $ext, string $description = ''): string
        {
-               return '[url=' . DI::baseUrl() . '/photos/' . $nickname . '/image/' . $resource_id . '][img=' . DI::baseUrl() . '/photo/' . $resource_id . '-' . $preview. '.' . $ext . ']' . $description . '[/img][/url]';
+               return self::getBBCodeByUrl(
+                       DI::baseUrl() . '/photos/' . $nickname . '/image/' . $resource_id,
+                       DI::baseUrl() . '/photo/' . $resource_id . '-' . $preview. '.' . $ext,
+                       $description
+               );
        }
 
        /**
-        * Get a link to a picture with a preview
+        * Get a BBCode tag for an image URL with a preview thumbnail and an image description
         *
-        * @param string $photo
-        * @param string $preview
+        * @param string $photo Full image URL
+        * @param string $preview Preview image URL
         * @param string $description
         * @return string
         */
-       public static function getPictureUrl(string $photo, string $preview, string $description): string
+       public static function getBBCodeByUrl(string $photo, string $preview = null, string $description = ''): string
+       {
+               if (!empty($preview)) {
+                       return '[url=' . $photo . '][img=' . $preview . ']' . $description . '[/img][/url]';
+               }
+
+               return '[img=' . $photo . ']' . $description . '[/img]';
+       }
+
+       /**
+        * Get the maximum possible upload size in bytes
+        *
+        * @return integer
+        */
+       public static function getMaxUploadBytes(): int
        {
-               return '[url=' . $photo . '][img=' . $preview . ']' . $description . '[/img][/url]';
+               $upload_size = ini_get('upload_max_filesize') ?: DI::config()->get('system', 'maximagesize');
+               return Strings::getBytesFromShorthand($upload_size);
        }
 }