[UI] Set html img width and height attributes for avatar

This commit is contained in:
Hugo Sales 2021-12-02 15:36:08 +00:00
parent 92d5f3ec1e
commit 772ec6efcf
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
3 changed files with 17 additions and 1 deletions

View File

@ -110,6 +110,16 @@ class Avatar extends Component
}
}
public static function getDimensions(int $actor_id, string $size = 'full')
{
try {
$attachment = self::getAvatar($actor_id)->getAttachment();
return ['width' => $attachment->getWidth(), 'height' => $attachment->getHeight()];
} catch (NoAvatarException) {
return ['width' => Common::config('thumbnail', 'small'), 'height' => Common::config('thumbnail', 'small')];
}
}
/**
* Get the cached avatar file info associated with the given Actor id
*

View File

@ -250,6 +250,11 @@ class Actor extends Entity
return Avatar::getAvatarUrl($this->getId(), $size);
}
public function getAvatarDimensions(string $size = 'full')
{
return Avatar::getDimensions($this->getId(), $size);
}
public static function getById(int $id): ?self
{
return Cache::get('actor-id-' . $id, fn () => DB::find('actor', ['id' => $id]));

View File

@ -1,5 +1,6 @@
{% set actor_nickname = actor.getNickname() %}
{% set actor_avatar = actor.getAvatarUrl() %}
{% set actor_avatar_dimensions = actor.getAvatarDimensions() %}
{% set actor_tags = actor.getSelfTags()[1] %} {# Take only the actor_tags, not the circles #}
{% set actor_bio = actor.getBio() %}
{% set actor_uri = actor.getUri() %}
@ -8,7 +9,7 @@
<section id='profile-{{ actor.id }}' class='profile' title="{{ actor_nickname }}'s {{ 'profile information.' | trans }}">
<a href="{{ actor_uri }}">
<div class="profile-info">
<img src='{{ actor_avatar }}' class="profile-avatar" alt="{{ actor_nickname }}{{ '\'s avatar.' | trans }}">
<img src="{{ actor_avatar }}" class="profile-avatar" alt="{% trans %} %actor_nickname%'s avatar. {% endtrans %}" width="{{actor_avatar_dimensions['width']}}" height="{{actor_avatar_dimensions['height']}}">
<strong class="profile-info-nickname" title="{{ actor_nickname }}{{ '\'s nickname.' | trans }}">{{ actor_nickname }}</strong>
<section class="profile-info-bio">