From 1f91663c2255dd6de6444a14d07f26fc4654641b Mon Sep 17 00:00:00 2001 From: John Schember Date: Thu, 2 Dec 2010 18:43:50 -0500 Subject: [PATCH 1/2] 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') From 6798036d8487844ee5a740e28b3cb68718929f81 Mon Sep 17 00:00:00 2001 From: John Schember Date: Thu, 2 Dec 2010 19:06:35 -0500 Subject: [PATCH 2/2] PMLZ Output: UI options. --- src/calibre/gui2/convert/pml_output.py | 22 ++++++++++++ src/calibre/gui2/convert/pmlz_output.ui | 48 +++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 src/calibre/gui2/convert/pml_output.py create mode 100644 src/calibre/gui2/convert/pmlz_output.ui diff --git a/src/calibre/gui2/convert/pml_output.py b/src/calibre/gui2/convert/pml_output.py new file mode 100644 index 0000000000..61207d3de5 --- /dev/null +++ b/src/calibre/gui2/convert/pml_output.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +__license__ = 'GPL 3' +__copyright__ = '2009, John Schember ' +__docformat__ = 'restructuredtext en' + +from calibre.gui2.convert.pmlz_output_ui import Ui_Form +from calibre.gui2.convert import Widget + +format_model = None + +class PluginWidget(Widget, Ui_Form): + + TITLE = _('PMLZ Output') + HELP = _('Options specific to')+' PMLZ '+_('output') + COMMIT_NAME = 'pmlz_output' + ICON = I('mimetypes/unknown.png') + + def __init__(self, parent, get_option, get_help, db=None, book_id=None): + Widget.__init__(self, parent, ['inline_toc', 'full_image_depth']) + self.db, self.book_id = db, book_id + self.initialize_options(get_option, get_help, db, book_id) diff --git a/src/calibre/gui2/convert/pmlz_output.ui b/src/calibre/gui2/convert/pmlz_output.ui new file mode 100644 index 0000000000..3573e14210 --- /dev/null +++ b/src/calibre/gui2/convert/pmlz_output.ui @@ -0,0 +1,48 @@ + + + Form + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Qt::Vertical + + + + 20 + 246 + + + + + + + + &Inline TOC + + + + + + + Do not reduce image size and depth + + + + + + + +