mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:...
This commit is contained in:
parent
606f3a6dd1
commit
18d9e00938
@ -92,41 +92,36 @@ class PageProcessor(list):
|
|||||||
|
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
try:
|
img = NewMagickWand()
|
||||||
img = NewMagickWand()
|
if img < 0:
|
||||||
if img < 0:
|
raise RuntimeError('Cannot create wand.')
|
||||||
|
if not MagickReadImage(img, self.path_to_page):
|
||||||
|
raise IOError('Failed to read image from: %'%self.path_to_page)
|
||||||
|
width = MagickGetImageWidth(img)
|
||||||
|
height = MagickGetImageHeight(img)
|
||||||
|
if self.num == 0: # First image so create a thumbnail from it
|
||||||
|
thumb = CloneMagickWand(img)
|
||||||
|
if thumb < 0:
|
||||||
raise RuntimeError('Cannot create wand.')
|
raise RuntimeError('Cannot create wand.')
|
||||||
if not MagickReadImage(img, self.path_to_page):
|
MagickThumbnailImage(thumb, 60, 80)
|
||||||
raise IOError('Failed to read image from: %'%self.path_to_page)
|
MagickWriteImage(thumb, os.path.join(self.dest, 'thumbnail.png'))
|
||||||
width = MagickGetImageWidth(img)
|
DestroyMagickWand(thumb)
|
||||||
height = MagickGetImageHeight(img)
|
|
||||||
if self.num == 0: # First image so create a thumbnail from it
|
self.pages = [img]
|
||||||
thumb = CloneMagickWand(img)
|
if self.num == 2:
|
||||||
if thumb < 0:
|
raise Exception('asd')
|
||||||
|
if width > height:
|
||||||
|
if self.opts.landscape:
|
||||||
|
self.rotate = True
|
||||||
|
else:
|
||||||
|
split1, split2 = map(CloneMagickWand, (img, img))
|
||||||
|
if split1 < 0 or split2 < 0:
|
||||||
raise RuntimeError('Cannot create wand.')
|
raise RuntimeError('Cannot create wand.')
|
||||||
MagickThumbnailImage(thumb, 60, 80)
|
DestroyMagickWand(img)
|
||||||
MagickWriteImage(thumb, os.path.join(self.dest, 'thumbnail.png'))
|
MagickCropImage(split1, (width/2)-1, height, 0, 0)
|
||||||
DestroyMagickWand(thumb)
|
MagickCropImage(split2, (width/2)-1, height, width/2, 0 )
|
||||||
|
self.pages = [split2, split1] if self.opts.right2left else [split1, split2]
|
||||||
self.pages = [img]
|
self.process_pages()
|
||||||
|
|
||||||
if width > height:
|
|
||||||
if self.opts.landscape:
|
|
||||||
self.rotate = True
|
|
||||||
else:
|
|
||||||
split1, split2 = map(CloneMagickWand, (img, img))
|
|
||||||
if split1 < 0 or split2 < 0:
|
|
||||||
raise RuntimeError('Cannot create wand.')
|
|
||||||
DestroyMagickWand(img)
|
|
||||||
MagickCropImage(split1, (width/2)-1, height, 0, 0)
|
|
||||||
MagickCropImage(split2, (width/2)-1, height, width/2, 0 )
|
|
||||||
self.pages = [split2, split1] if self.opts.right2left else [split1, split2]
|
|
||||||
self.process_pages()
|
|
||||||
except Exception, err:
|
|
||||||
print 'Failed to process page: %s'%os.path.basename(self.path_to_page)
|
|
||||||
print 'Error:', err
|
|
||||||
if self.opts.verbose:
|
|
||||||
traceback.print_exc()
|
|
||||||
|
|
||||||
def process_pages(self):
|
def process_pages(self):
|
||||||
for i, wand in enumerate(self.pages):
|
for i, wand in enumerate(self.pages):
|
||||||
@ -195,16 +190,19 @@ def process_page(path, dest, opts, num):
|
|||||||
|
|
||||||
class Progress(object):
|
class Progress(object):
|
||||||
|
|
||||||
def __init__(self, total, update):
|
def __init__(self, total, update, verbose):
|
||||||
self.total = total
|
self.total = total
|
||||||
self.update = update
|
self.update = update
|
||||||
self.done = 0
|
self.done = 0
|
||||||
|
self.verbose = verbose
|
||||||
|
|
||||||
def __call__(self, job):
|
def __call__(self, job):
|
||||||
self.done += 1
|
self.done += 1
|
||||||
msg = _('Rendered %s') if job.result else _('Failed %s')
|
msg = _('Rendered %s') if job.result else _('Failed %s')
|
||||||
msg = msg%os.path.basename(job.args[0])
|
msg = msg%os.path.basename(job.args[0])
|
||||||
self.update(float(self.done)/self.total, msg)
|
self.update(float(self.done)/self.total, msg)
|
||||||
|
if not job.result and self.verbose:
|
||||||
|
print job.traceback
|
||||||
|
|
||||||
def process_pages(pages, opts, update):
|
def process_pages(pages, opts, update):
|
||||||
'''
|
'''
|
||||||
@ -214,7 +212,7 @@ def process_pages(pages, opts, update):
|
|||||||
raise RuntimeError('Failed to load ImageMagick')
|
raise RuntimeError('Failed to load ImageMagick')
|
||||||
|
|
||||||
tdir = PersistentTemporaryDirectory('_comic2lrf_pp')
|
tdir = PersistentTemporaryDirectory('_comic2lrf_pp')
|
||||||
notify = Progress(len(pages), update)
|
notify = Progress(len(pages), update, opts.verbose)
|
||||||
server = Server()
|
server = Server()
|
||||||
jobs = []
|
jobs = []
|
||||||
for i, path in enumerate(pages):
|
for i, path in enumerate(pages):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user