use smaller versions of lemmy images #159

This commit is contained in:
rimu 2024-05-06 15:42:12 +12:00
parent 45e19723ff
commit f0d229c423
3 changed files with 8 additions and 10 deletions

View file

@ -204,9 +204,12 @@ class File(db.Model):
thumbnail_width = db.Column(db.Integer)
thumbnail_height = db.Column(db.Integer)
def view_url(self):
def view_url(self, resize=False):
if self.source_url:
return self.source_url
if resize and '/pictrs/' in self.source_url and '?' not in self.source_url:
return f'{self.source_url}?thumbnail=1024'
else:
return self.source_url
elif self.file_path:
file_path = self.file_path[4:] if self.file_path.startswith('app/') else self.file_path
return f"https://{current_app.config['SERVER_NAME']}/{file_path}"

View file

@ -32,10 +32,10 @@
<div class="post_image">
{% if post.image_id %}
{% if low_bandwidth %}
<a href="{{ post.image.view_url() }}" rel="nofollow ugc"><img src="{{ post.image.medium_url() }}" alt="{{ post.image.alt_text if post.image.alt_text else post.title }}"
<a href="{{ post.image.view_url(resize=True) }}" rel="nofollow ugc"><img src="{{ post.image.medium_url() }}" alt="{{ post.image.alt_text if post.image.alt_text else post.title }}"
width="{{ post.image.width }}" height="{{ post.image.height }}" /></a>
{% else %}
<a href="{{ post.image.view_url() }}" rel="nofollow ugc"><img src="{{ post.image.view_url() }}" alt="{{ post.image.alt_text if post.image.alt_text else post.title }}"></a>
<a href="{{ post.image.view_url() }}" rel="nofollow ugc"><img src="{{ post.image.view_url(resize=True) }}" alt="{{ post.image.alt_text if post.image.alt_text else post.title }}"></a>
{% endif %}
{% else %}
<a href="{{ post.url }}" rel="nofollow ugc" target="_blank" aria-label="Go to image"><img src="{{ post.url }}" style="max-width: 100%; height: auto;" /></a>

View file

@ -7,11 +7,6 @@
<div class="item{{ ' reported' if post.reports > 0 and current_user.is_authenticated and post.community.is_moderator() }}{{ ' blocked' if content_blocked }}"
{% if content_blocked %} title="{{ _('Filtered: ') }}{{ content_blocked }}"{% endif %}>
{% if post.image_id %}
{% if post_layout == 'masonry' or low_bandwidth %}
{% set thumbnail = post.image.thumbnail_url() %}
{% elif post_layout == 'masonry_wide' %}
{% set thumbnail = post.image.view_url() %}
{% endif %}
<div class="masonry_thumb" title="{{ post_title }}">
{% if post.type == POST_TYPE_LINK or post.type == POST_TYPE_VIDEO %}
{% if post.image.medium_url() %}
@ -27,7 +22,7 @@
loading="{{ 'lazy' if low_bandwidth else 'eager' }}" /></a>
{% endif %}
{% elif post.type == POST_TYPE_IMAGE %}
<a href="{{ post.image.view_url() }}" rel="nofollow ugc" target="_blank"><img src="{{ post.image.medium_url() }}"
<a href="{{ post.image.view_url(resize=True) }}" rel="nofollow ugc" target="_blank"><img src="{{ post.image.medium_url() }}"
alt="{{ post.image.alt_text if post.image.alt_text else '' }}" title="{{ post_title }}"
loading="lazy" width="{{ post.image.width }}" height="{{ post.image.height }}" /></a>
{% else %}