mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
PMLZ Output: Reduce image depth and size by default to accommodate Dropbook. Includes option to output un-modified images.
This commit is contained in:
parent
8032890d0f
commit
1f91663c22
@ -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():
|
||||
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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user