diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index f6e24fdb39..53395aa472 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -32,7 +32,7 @@ from calibre.devices.folder_device.driver import FOLDER_DEVICE from calibre.devices.bambook.driver import BAMBOOK, BAMBOOKWifi from calibre.constants import DEBUG from calibre.utils.config import tweaks, device_prefs -from calibre.utils.magick.draw import thumbnail +from calibre.utils.img import scale_image from calibre.library.save_to_disk import find_plugboard from calibre.ptempfile import PersistentTemporaryFile, force_unicode as filename_to_unicode # }}} @@ -926,7 +926,7 @@ class DeviceMixin(object): # {{{ def set_default_thumbnail(self, height): img = I('book.png', data=True) - self.default_thumbnail = thumbnail(img, height, height) + self.default_thumbnail = scale_image(img, height, height, preserve_aspect_ratio=False) def connect_to_folder_named(self, folder): if os.path.exists(folder) and os.path.isdir(folder): @@ -1282,7 +1282,7 @@ class DeviceMixin(object): # {{{ if self.device_manager.device and \ hasattr(self.device_manager.device, 'THUMBNAIL_WIDTH'): try: - return thumbnail(data, + return scale_image(data, self.device_manager.device.THUMBNAIL_WIDTH, self.device_manager.device.THUMBNAIL_HEIGHT, preserve_aspect_ratio=False) @@ -1292,7 +1292,7 @@ class DeviceMixin(object): # {{{ ht = self.device_manager.device.THUMBNAIL_HEIGHT \ if self.device_manager else DevicePlugin.THUMBNAIL_HEIGHT try: - return thumbnail(data, ht, ht, + return scale_image(data, ht, ht, compression_quality=self.device_manager.device.THUMBNAIL_COMPRESSION_QUALITY) except: pass diff --git a/src/calibre/gui2/store/search/download_thread.py b/src/calibre/gui2/store/search/download_thread.py index c8e93f290d..3781496bf0 100644 --- a/src/calibre/gui2/store/search/download_thread.py +++ b/src/calibre/gui2/store/search/download_thread.py @@ -13,7 +13,7 @@ from Queue import Queue from calibre import browser from calibre.constants import DEBUG -from calibre.utils.magick.draw import thumbnail +from calibre.utils.img import scale_image class GenericDownloadThreadPool(object): ''' @@ -161,7 +161,7 @@ class CoverThread(Thread): if result and result.cover_url: with closing(self.br.open(result.cover_url, timeout=timeout)) as f: result.cover_data = f.read() - result.cover_data = thumbnail(result.cover_data, 64, 64)[2] + result.cover_data = scale_image(result.cover_data, 64, 64)[2] callback() self.tasks.task_done() except: diff --git a/src/calibre/utils/img.py b/src/calibre/utils/img.py index aa8d1c37ca..605305496c 100644 --- a/src/calibre/utils/img.py +++ b/src/calibre/utils/img.py @@ -16,10 +16,11 @@ def image_from_data(data): return i def scale_image(data, width=60, height=80, compression_quality=70, as_png=False, preserve_aspect_ratio=True): + ''' Scale an image, returning it as either JPEG or PNG data (bytestring). + Transparency is alpha blended with white when converting to JPEG. Is thread + safe and does not require a QApplication. ''' # We use Qt instead of ImageMagick here because ImageMagick seems to use - # some kind of memory pool, causing memory consumption to sky rocket. Since - # we are only using QImage this method is thread safe, and does not require - # a QApplication/GUI thread + # some kind of memory pool, causing memory consumption to sky rocket. if isinstance(data, QImage): img = data else: @@ -47,5 +48,3 @@ def scale_image(data, width=60, height=80, compression_quality=70, as_png=False, if not img.save(buf, fmt, quality=compression_quality): raise ValueError('Failed to export thumbnail image to: ' + fmt) return img.width(), img.height(), ba.data() - -