From 47936e34a74c2afbc5311cb258c53bed40a2688f Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 3 Jun 2011 17:57:56 +0200 Subject: [PATCH 1/4] improved thumbnail creation speed --- openlp/core/lib/mediamanageritem.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 31890a252..0f6c24829 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -391,21 +391,23 @@ class MediaManagerItem(QtGui.QWidget): self.iconFromFile(image, thumb) return True - def iconFromFile(self, image, thumb): + def iconFromFile(self, image_path, thumb_path): """ Create a thumbnail icon from a given image. - ``image`` + ``image_path`` The image file to create the icon from. - ``thumb`` - The filename to save the thumbnail to + ``thumb_path`` + The filename to save the thumbnail to. """ - icon = build_icon(unicode(image)) - pixmap = icon.pixmap(QtCore.QSize(88, 50)) - ext = os.path.splitext(thumb)[1].lower() - pixmap.save(thumb, ext[1:]) - return icon + ext = os.path.splitext(thumb_path)[1].lower() + reader = QtGui.QImageReader(image_path) + reader.setScaledSize(QtCore.QSize( + reader.size().width() / reader.size().height() * 88, 88)) + thumb = reader.read() + thumb.save(thumb_path, ext[1:]) + return build_icon(unicode(thumb_path)) def loadList(self, list): raise NotImplementedError(u'MediaManagerItem.loadList needs to be ' From e08c65aa45ee047074bae86726711017ed33ea8d Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 5 Jun 2011 18:33:28 +0200 Subject: [PATCH 2/4] fixed ratio --- openlp/core/lib/mediamanageritem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 0f6c24829..954179288 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -403,8 +403,8 @@ class MediaManagerItem(QtGui.QWidget): """ ext = os.path.splitext(thumb_path)[1].lower() reader = QtGui.QImageReader(image_path) - reader.setScaledSize(QtCore.QSize( - reader.size().width() / reader.size().height() * 88, 88)) + ratio = float(reader.size().width()) / float(reader.size().height()) + reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88)) thumb = reader.read() thumb.save(thumb_path, ext[1:]) return build_icon(unicode(thumb_path)) From 98e731ee9a340040ac6230779ce72d501a19ed34 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 6 Jun 2011 09:05:10 +0200 Subject: [PATCH 3/4] fallback if thumb was not created --- openlp/core/lib/mediamanageritem.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 954179288..9aa159981 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -407,7 +407,11 @@ class MediaManagerItem(QtGui.QWidget): reader.setScaledSize(QtCore.QSize(int(ratio * 88), 88)) thumb = reader.read() thumb.save(thumb_path, ext[1:]) - return build_icon(unicode(thumb_path)) + if os.path.exists(thumb_path): + return build_icon(unicode(thumb_path)) + # When the thumbnail creation was not successful then create the icon + # from the original file. + return build_icon(unicode(image_path)) def loadList(self, list): raise NotImplementedError(u'MediaManagerItem.loadList needs to be ' From 5d9e6acfbf1aa916bfc9ea7e606d3e0ddd5fa03a Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 6 Jun 2011 16:58:14 +0200 Subject: [PATCH 4/4] better comment --- openlp/core/lib/mediamanageritem.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 9aa159981..cfd4948cb 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -409,8 +409,7 @@ class MediaManagerItem(QtGui.QWidget): thumb.save(thumb_path, ext[1:]) if os.path.exists(thumb_path): return build_icon(unicode(thumb_path)) - # When the thumbnail creation was not successful then create the icon - # from the original file. + # Fallback for files with animation support. return build_icon(unicode(image_path)) def loadList(self, list):