mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Speed up generation of thumbnails for catalog
This commit is contained in:
parent
6b59d8aa96
commit
0b4de38330
@ -751,7 +751,9 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
self.generateHTMLByTags()
|
self.generateHTMLByTags()
|
||||||
|
|
||||||
if getattr(self.reporter, 'cancel_requested', False): return 1
|
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
|
if getattr(self.reporter, 'cancel_requested', False): return 1
|
||||||
self.generateOPF()
|
self.generateOPF()
|
||||||
@ -2343,29 +2345,28 @@ class EPUB_MOBI(CatalogPlugin):
|
|||||||
|
|
||||||
def generateThumbnail(self, title, image_dir, thumb_file):
|
def generateThumbnail(self, title, image_dir, thumb_file):
|
||||||
import calibre.utils.PythonMagickWand as pw
|
import calibre.utils.PythonMagickWand as pw
|
||||||
with pw.ImageMagick():
|
try:
|
||||||
try:
|
img = pw.NewMagickWand()
|
||||||
img = pw.NewMagickWand()
|
if img < 0:
|
||||||
if img < 0:
|
raise RuntimeError('generate_thumbnail(): Cannot create wand')
|
||||||
raise RuntimeError('generate_thumbnail(): Cannot create wand')
|
# Read the cover
|
||||||
# Read the cover
|
if not pw.MagickReadImage(img,
|
||||||
if not pw.MagickReadImage(img,
|
title['cover'].encode(filesystem_encoding)):
|
||||||
title['cover'].encode(filesystem_encoding)):
|
print 'Failed to read cover image from: %s' % title['cover']
|
||||||
print 'Failed to read cover image from: %s' % title['cover']
|
raise IOError
|
||||||
raise IOError
|
thumb = pw.CloneMagickWand(img)
|
||||||
thumb = pw.CloneMagickWand(img)
|
if thumb < 0:
|
||||||
if thumb < 0:
|
print 'generate_thumbnail(): Cannot clone cover'
|
||||||
print 'generate_thumbnail(): Cannot clone cover'
|
raise RuntimeError
|
||||||
raise RuntimeError
|
# img, width, height
|
||||||
# img, width, height
|
pw.MagickThumbnailImage(thumb, 75, 100)
|
||||||
pw.MagickThumbnailImage(thumb, 75, 100)
|
pw.MagickWriteImage(thumb, os.path.join(image_dir, thumb_file))
|
||||||
pw.MagickWriteImage(thumb, os.path.join(image_dir, thumb_file))
|
pw.DestroyMagickWand(thumb)
|
||||||
pw.DestroyMagickWand(thumb)
|
pw.DestroyMagickWand(img)
|
||||||
pw.DestroyMagickWand(img)
|
except IOError:
|
||||||
except IOError:
|
print "generate_thumbnail() IOError with %s" % title['title']
|
||||||
print "generate_thumbnail() IOError with %s" % title['title']
|
except RuntimeError:
|
||||||
except RuntimeError:
|
print "generate_thumbnail() RuntimeError with %s" % title['title']
|
||||||
print "generate_thumbnail() RuntimeError with %s" % title['title']
|
|
||||||
|
|
||||||
def processSpecialTags(self, tags, this_title, opts):
|
def processSpecialTags(self, tags, this_title, opts):
|
||||||
tag_list = []
|
tag_list = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user