From 40808b4a1b5e257ba1465b55e251931c9bae5ad4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 16 Oct 2010 09:04:38 -0600 Subject: [PATCH] /browse: Preserve aspect ratio when resizing category icons --- src/calibre/library/server/browse.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/library/server/browse.py b/src/calibre/library/server/browse.py index d3cfc0e84a..5e24bb1bc7 100644 --- a/src/calibre/library/server/browse.py +++ b/src/calibre/library/server/browse.py @@ -12,7 +12,8 @@ from binascii import hexlify, unhexlify import cherrypy from calibre.constants import filesystem_encoding -from calibre import isbytestring, force_unicode, prepare_string_for_xml as xml +from calibre import isbytestring, force_unicode, fit_image, \ + prepare_string_for_xml as xml from calibre.utils.ordered_dict import OrderedDict from calibre.utils.filenames import ascii_filename from calibre.utils.config import prefs @@ -267,7 +268,10 @@ class BrowseServer(object): raise cherrypy.HTTPError(404, 'no icon named: %r'%name) img = Image() img.load(data) - img.size = (48, 48) + width, height = img.size + scaled, width, height = fit_image(width, height, 48, 48) + if scaled: + img.size = (width, height) cherrypy.response.headers['Content-Type'] = 'image/png' cherrypy.response.headers['Last-Modified'] = self.last_modified(self.build_time) @@ -277,7 +281,7 @@ class BrowseServer(object): categories = self.categories_cache() category_meta = self.db.field_metadata cats = [ - (_('Newest'), 'newest', 'blank.png'), + (_('Newest'), 'newest', 'forward.png'), ] def getter(x):