Preserve aspect ratio of album covers in grid views (close #111)

This commit is contained in:
Olli 2026-01-10 16:22:03 +01:00
commit 9b29f7b274
3 changed files with 24 additions and 19 deletions

View file

@ -444,15 +444,9 @@ class LibraryPanel(Adw.Bin):
self.standalone_image.set_pixel_size(min(size_width, size_height)/2)
return
# Skalierungswert für Breite und Höhe ermitteln
ratio_w = float(size_width) / float(pixbuf.get_width())
ratio_h = float(size_height) / float(pixbuf.get_height())
# Kleineren beider Skalierungswerte nehmen, nicht Hochskalieren
ratio = min(ratio_w, ratio_h)
ratio = min(ratio, 1)
# Neue Breite und Höhe berechnen
width = int(math.floor(pixbuf.get_width() * ratio))
height = int(math.floor(pixbuf.get_height() * ratio))
(width, height) = Utils.calculate_size(pixbuf.get_width(),
pixbuf.get_height(), size_width,
size_height)
if width <= 0 or height <= 0:
return
# Pixelpuffer auf Oberfläche zeichnen

View file

@ -252,15 +252,9 @@ class PlaylistPanel(Adw.Bin):
self.standalone_image.set_pixel_size(min(size_width, size_height)/2)
return
# Skalierungswert für Breite und Höhe ermitteln
ratio_w = float(size_width) / float(pixbuf.get_width())
ratio_h = float(size_height) / float(pixbuf.get_height())
# Kleineren beider Skalierungswerte nehmen, nicht Hochskalieren
ratio = min(ratio_w, ratio_h)
ratio = min(ratio, 1)
# Neue Breite und Höhe berechnen
width = int(math.floor(pixbuf.get_width() * ratio))
height = int(math.floor(pixbuf.get_height() * ratio))
(width, height) = Utils.calculate_size(pixbuf.get_width(),
pixbuf.get_height(), size_width,
size_height)
if width <= 0 or height <= 0:
return
# Pixelpuffer auf Oberfläche zeichnen

View file

@ -2,6 +2,7 @@
import gi
import hashlib
import math
import locale
import logging
import os
@ -36,7 +37,10 @@ class Utils:
if albumart:
pixbuf = Utils.load_pixbuf(albumart)
if pixbuf is not None:
pixbuf = pixbuf.scale_simple(size, size,
(width, height) = Utils.calculate_size(pixbuf.get_width(),
pixbuf.get_height(),
size, size)
pixbuf = pixbuf.scale_simple(width, height,
GdkPixbuf.InterpType.HYPER)
try:
pixbuf.savev(cache_url, 'jpeg', [], [])
@ -78,6 +82,19 @@ class Utils:
m.update(value.encode('utf-8'))
return m.hexdigest()
@staticmethod
def calculate_size(src_width, src_height, dest_width, dest_height):
ratio_w = float(dest_width) / float(src_width)
ratio_h = float(dest_height) / float(src_height)
ratio = min(min(ratio_w, ratio_h), 1)
if ratio == 1:
return (src_width, src_height)
width = int(math.floor(src_width * ratio))
height = int(math.floor(src_height * ratio))
return (width, height)
class SortOrder:
ARTIST = 0