mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added epub_max_image_width configuration option.
This commit is contained in:
parent
fe07254b9c
commit
246d07807d
@ -39,6 +39,7 @@ epub_exclude_files = ['_static/opensearch.xml', '_static/doctools.js',
|
||||
'_static/jquery.js', '_static/searchtools.js', '_static/underscore.js',
|
||||
'_static/basic.css', 'search.html']
|
||||
epub_fix_images = False
|
||||
epub_max_image_width = 0
|
||||
|
||||
latex_documents = [('contents', 'sphinx.tex', 'Sphinx Documentation',
|
||||
'Georg Brandl', 'manual', 1)]
|
||||
|
@ -812,6 +812,15 @@ the `Dublin Core metadata <http://dublincore.org/>`_.
|
||||
to use this option. The default value is ``False`` because the automatic
|
||||
conversion may loose information.
|
||||
|
||||
.. confval:: epub_max_image_width
|
||||
|
||||
This option specifies the maximum width of images. If it is set to a value
|
||||
greater than zero, images with a width larger than the given value are
|
||||
scaled accordingly. If it is zero, no scaling is performed. The default
|
||||
value is ``0``. You need the Python Image Library (PIL) installed to use
|
||||
this option.
|
||||
|
||||
|
||||
.. _latex-options:
|
||||
|
||||
Options for LaTeX output
|
||||
|
@ -311,7 +311,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
||||
def copy_image_files_pil(self):
|
||||
"""Copy images using the PIL.
|
||||
The method tries to read and write the files with the PIL,
|
||||
converting the format if necessary/possible.
|
||||
converting the format and resizing the image if necessary/possible.
|
||||
"""
|
||||
ensuredir(path.join(self.outdir, '_images'))
|
||||
for src in self.status_iterator(self.images, 'copying images... ',
|
||||
@ -329,9 +329,16 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
||||
self.warn('cannot copy image file %r: %s' %
|
||||
(path.join(self.srcdir, src), err))
|
||||
continue
|
||||
if img.mode in ('P',):
|
||||
# See PIL documentation for Image.convert()
|
||||
img = img.convert()
|
||||
if self.config.epub_fix_images:
|
||||
if img.mode in ('P',):
|
||||
# See PIL documentation for Image.convert()
|
||||
img = img.convert()
|
||||
if self.config.epub_max_image_width > 0:
|
||||
(width, height) = img.size
|
||||
nw = self.config.epub_max_image_width
|
||||
if width > nw:
|
||||
nh = (height * nw) / width
|
||||
img = img.resize((nw, nh), Image.BICUBIC)
|
||||
try:
|
||||
img.save(path.join(self.outdir, '_images', dest))
|
||||
except IOError, err:
|
||||
@ -343,7 +350,7 @@ class EpubBuilder(StandaloneHTMLBuilder):
|
||||
This overwritten method can use the PIL to convert image files.
|
||||
"""
|
||||
if self.images:
|
||||
if self.config.epub_fix_images:
|
||||
if self.config.epub_fix_images or self.config.epub_max_image_width:
|
||||
if not Image:
|
||||
self.warn('PIL not found - copying image files')
|
||||
super(EpubBuilder, self).copy_image_files()
|
||||
|
@ -127,6 +127,7 @@ class Config(object):
|
||||
epub_tocdepth = (3, 'env'),
|
||||
epub_tocdup = (True, 'env'),
|
||||
epub_fix_images = (False, 'html'),
|
||||
epub_max_image_width = (0, 'html'),
|
||||
|
||||
# LaTeX options
|
||||
latex_documents = ([], None),
|
||||
|
@ -288,6 +288,9 @@ epub_copyright = u'%(copyright_str)s'
|
||||
|
||||
# Fix unsupported image types using the PIL.
|
||||
#epub_fix_images = False
|
||||
|
||||
# Scale large images.
|
||||
#epub_max_image_width = 0
|
||||
'''
|
||||
|
||||
INTERSPHINX_CONFIG = '''
|
||||
|
Loading…
Reference in New Issue
Block a user