Preserve aspect ratio of album covers in grid views (close #111)
This commit is contained in:
parent
0a109bc886
commit
9b29f7b274
3 changed files with 24 additions and 19 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
19
src/utils.py
19
src/utils.py
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue