From 0b4de383306480d753be5be3fd01bca090c1dbab Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 24 Jan 2010 11:34:42 -0700 Subject: [PATCH] Speed up generation of thumbnails for catalog --- src/calibre/library/catalog.py | 49 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/calibre/library/catalog.py b/src/calibre/library/catalog.py index ea0a9005d2..f6d8017156 100644 --- a/src/calibre/library/catalog.py +++ b/src/calibre/library/catalog.py @@ -751,7 +751,9 @@ class EPUB_MOBI(CatalogPlugin): self.generateHTMLByTags() if getattr(self.reporter, 'cancel_requested', False): return 1 - self.generateThumbnails() + from calibre.utils.PythonMagickWand import ImageMagick + with ImageMagick(): + self.generateThumbnails() if getattr(self.reporter, 'cancel_requested', False): return 1 self.generateOPF() @@ -2343,29 +2345,28 @@ class EPUB_MOBI(CatalogPlugin): def generateThumbnail(self, title, image_dir, thumb_file): import calibre.utils.PythonMagickWand as pw - with pw.ImageMagick(): - try: - img = pw.NewMagickWand() - if img < 0: - raise RuntimeError('generate_thumbnail(): Cannot create wand') - # Read the cover - if not pw.MagickReadImage(img, - title['cover'].encode(filesystem_encoding)): - print 'Failed to read cover image from: %s' % title['cover'] - raise IOError - thumb = pw.CloneMagickWand(img) - if thumb < 0: - print 'generate_thumbnail(): Cannot clone cover' - raise RuntimeError - # img, width, height - pw.MagickThumbnailImage(thumb, 75, 100) - pw.MagickWriteImage(thumb, os.path.join(image_dir, thumb_file)) - pw.DestroyMagickWand(thumb) - pw.DestroyMagickWand(img) - except IOError: - print "generate_thumbnail() IOError with %s" % title['title'] - except RuntimeError: - print "generate_thumbnail() RuntimeError with %s" % title['title'] + try: + img = pw.NewMagickWand() + if img < 0: + raise RuntimeError('generate_thumbnail(): Cannot create wand') + # Read the cover + if not pw.MagickReadImage(img, + title['cover'].encode(filesystem_encoding)): + print 'Failed to read cover image from: %s' % title['cover'] + raise IOError + thumb = pw.CloneMagickWand(img) + if thumb < 0: + print 'generate_thumbnail(): Cannot clone cover' + raise RuntimeError + # img, width, height + pw.MagickThumbnailImage(thumb, 75, 100) + pw.MagickWriteImage(thumb, os.path.join(image_dir, thumb_file)) + pw.DestroyMagickWand(thumb) + pw.DestroyMagickWand(img) + except IOError: + print "generate_thumbnail() IOError with %s" % title['title'] + except RuntimeError: + print "generate_thumbnail() RuntimeError with %s" % title['title'] def processSpecialTags(self, tags, this_title, opts): tag_list = []