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)
|
self.standalone_image.set_pixel_size(min(size_width, size_height)/2)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Skalierungswert für Breite und Höhe ermitteln
|
(width, height) = Utils.calculate_size(pixbuf.get_width(),
|
||||||
ratio_w = float(size_width) / float(pixbuf.get_width())
|
pixbuf.get_height(), size_width,
|
||||||
ratio_h = float(size_height) / float(pixbuf.get_height())
|
size_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))
|
|
||||||
if width <= 0 or height <= 0:
|
if width <= 0 or height <= 0:
|
||||||
return
|
return
|
||||||
# Pixelpuffer auf Oberfläche zeichnen
|
# 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)
|
self.standalone_image.set_pixel_size(min(size_width, size_height)/2)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Skalierungswert für Breite und Höhe ermitteln
|
(width, height) = Utils.calculate_size(pixbuf.get_width(),
|
||||||
ratio_w = float(size_width) / float(pixbuf.get_width())
|
pixbuf.get_height(), size_width,
|
||||||
ratio_h = float(size_height) / float(pixbuf.get_height())
|
size_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))
|
|
||||||
if width <= 0 or height <= 0:
|
if width <= 0 or height <= 0:
|
||||||
return
|
return
|
||||||
# Pixelpuffer auf Oberfläche zeichnen
|
# Pixelpuffer auf Oberfläche zeichnen
|
||||||
|
|
|
||||||
19
src/utils.py
19
src/utils.py
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import gi
|
import gi
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import math
|
||||||
import locale
|
import locale
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
@ -36,7 +37,10 @@ class Utils:
|
||||||
if albumart:
|
if albumart:
|
||||||
pixbuf = Utils.load_pixbuf(albumart)
|
pixbuf = Utils.load_pixbuf(albumart)
|
||||||
if pixbuf is not None:
|
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)
|
GdkPixbuf.InterpType.HYPER)
|
||||||
try:
|
try:
|
||||||
pixbuf.savev(cache_url, 'jpeg', [], [])
|
pixbuf.savev(cache_url, 'jpeg', [], [])
|
||||||
|
|
@ -78,6 +82,19 @@ class Utils:
|
||||||
m.update(value.encode('utf-8'))
|
m.update(value.encode('utf-8'))
|
||||||
return m.hexdigest()
|
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:
|
class SortOrder:
|
||||||
ARTIST = 0
|
ARTIST = 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue