X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FUtil%2FImages.php;h=130544130493ccdc6d4fd9a45c887127d831ad9f;hb=d4a5a8051ad34a7be72238967afb3e6b140afdc8;hp=a6a9f4f7db78f66255bf86f9dbf457521742afa6;hpb=baf2f7565a0929acdce4d5e363441f886ad57f74;p=friendica.git diff --git a/src/Util/Images.php b/src/Util/Images.php index a6a9f4f7db..1305441304 100644 --- a/src/Util/Images.php +++ b/src/Util/Images.php @@ -1,6 +1,6 @@ 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,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; } /** @@ -311,4 +318,51 @@ class Images return ['width' => $dest_width, 'height' => $dest_height]; } + + /** + * 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 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 getBBCodeByResource(string $resource_id, string $nickname, int $preview, string $ext, string $description = ''): string + { + return self::getBBCodeByUrl( + DI::baseUrl() . '/photos/' . $nickname . '/image/' . $resource_id, + DI::baseUrl() . '/photo/' . $resource_id . '-' . $preview. '.' . $ext, + $description + ); + } + + /** + * Get a BBCode tag for an image URL with a preview thumbnail and an image description + * + * @param string $photo Full image URL + * @param string $preview Preview image URL + * @param string $description + * @return 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 + { + $upload_size = ini_get('upload_max_filesize') ?: DI::config()->get('system', 'maximagesize'); + return Strings::getBytesFromShorthand($upload_size); + } }