diff options
Diffstat (limited to 'src/web/helper/image.php')
-rw-r--r-- | src/web/helper/image.php | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/src/web/helper/image.php b/src/web/helper/image.php index 8815a6c..1b6650f 100644 --- a/src/web/helper/image.php +++ b/src/web/helper/image.php @@ -1,6 +1,14 @@ <?php /* Copyright (c) 2024 Freya Murphy */ -function image($src, $class = NULL, $link = NULL, $click = NULL): string { +function image( + $src, + $class = NULL, + $link = NULL, + $click = NULL, + $height = NULL, + $width = NULL, + $mime = NULL, +): string { if ($class) { $class = 'image-loading ' . $class; } else { @@ -9,6 +17,11 @@ function image($src, $class = NULL, $link = NULL, $click = NULL): string { $content = ''; + // dont need mime for images + if ($mime && strpos($mime, 'image') !== FALSE) { + $mime = NULL; + } + if ($link) { $content .= '<a class="' . $class . '" href="' . $link . '">'; } else if ($click) { @@ -16,7 +29,22 @@ function image($src, $class = NULL, $link = NULL, $click = NULL): string { } else { $content .= '<span class="' . $class . '">'; } - $content .= '<img src="' . $src . '" onerror="onImgError(this)" onload="onImgLoad(this)"/>'; + if ($mime) { + $content .= '<object class="inner" type="' . $mime . '" data="' . $src . '" '; + } else { + $content .= '<img class="inner" src="' . $src . '" '; + } + if ($height) { + $content .= "height=\"{$height}\" "; + } + if ($width) { + $content .= "width=\"{$width}\" "; + } + if ($mime) { + $content .= '></object>'; + } else { + $content .= 'onerror="onImgError(this)" onload="onImgLoad(this)"/>'; + } if ($link) { $content .= '</a>'; } else if ($click) { @@ -36,5 +64,14 @@ function pfp( if ($link === TRUE) { $link = '/profile?id=' . $user['id']; } - return image('/api/rpc/profile_avatar?user_id=' . $user['id'], 'pfp', link: $link, click: $click); + $mime = NULL; + if (isset($user['avatar_mime'])) { + $mime = $user['avatar_mime']; + } + return image('/api/rpc/profile_avatar?user_id=' . $user['id'], + 'pfp', + link: $link, + click: $click, + mime: $mime + ); } |