From 1f91663c2255dd6de6444a14d07f26fc4654641b Mon Sep 17 00:00:00 2001 From: John Schember Date: Thu, 2 Dec 2010 18:43:50 -0500 Subject: [PATCH] PMLZ Output: Reduce image depth and size by default to accommodate Dropbook. Includes option to output un-modified images. --- src/calibre/ebooks/pml/output.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/pml/output.py b/src/calibre/ebooks/pml/output.py index 774fc4c8d1..7e3729aa4a 100644 --- a/src/calibre/ebooks/pml/output.py +++ b/src/calibre/ebooks/pml/output.py @@ -35,6 +35,12 @@ class PMLOutput(OutputFormatPlugin): OptionRecommendation(name='inline_toc', recommended_value=False, level=OptionRecommendation.LOW, help=_('Add Table of Contents to beginning of the book.')), + OptionRecommendation(name='full_image_depth', + recommended_value=False, level=OptionRecommendation.LOW, + help=_('Do not reduce the size or bit depth of images. Images ' \ + 'have their size and depth reduced by default to accommodate ' \ + 'applications that can not convert images on their ' \ + 'own such as Dropbook.')), ]) def convert(self, oeb_book, output_path, input_plugin, opts, log): @@ -44,16 +50,20 @@ class PMLOutput(OutputFormatPlugin): with open(os.path.join(tdir, 'index.pml'), 'wb') as out: out.write(pml.encode(opts.output_encoding, 'replace')) - self.write_images(oeb_book.manifest, pmlmlizer.image_hrefs, tdir) + self.write_images(oeb_book.manifest, pmlmlizer.image_hrefs, tdir, opts) log.debug('Compressing output...') pmlz = ZipFile(output_path, 'w') pmlz.add_dir(tdir) - def write_images(self, manifest, image_hrefs, out_dir): + def write_images(self, manifest, image_hrefs, out_dir, opts): for item in manifest: if item.media_type in OEB_RASTER_IMAGES and item.href in image_hrefs.keys(): - im = Image.open(cStringIO.StringIO(item.data)) + if opts.full_image_depth: + im = Image.open(cStringIO.StringIO(item.data)) + else: + im = Image.open(cStringIO.StringIO(item.data)).convert('P') + im.thumbnail((300,300), Image.ANTIALIAS) data = cStringIO.StringIO() im.save(data, 'PNG')