chip schrieb:
> Guys,
> 
> I'm wondering if there is a way to specify the maximum dimensions of
> an image so that large images would be displayed using a reasonable
> size, but small images would remain unchanged.
> 
> I haven't been able to find any native support for doing this in
> restructured text or Sphinx.  So I am curious how others are handling
> image sizes in documentation.  Are people handling images on a case by
> case basis since they are relatively uncommon?  Is trying to handle it
> automatically a bad idea somehow?
> 
> Also if I wanted add the functionality to Sphinx to do this for myself
> where would be the right place to do it?
> 
> I am still becoming familiar with Sphinx, but it seems that this
> should be added in the builders somewhere.  I am looking at an example
> uploaded for Clickable, scaled, images submitted by Sebastian in the
> thread:
> http://groups.google.com/group/sphinx-dev/browse_thread/thread/c4bbe9631a30302b/830a61020d5af6e8?hl=en&lnk=gst&q=clickable+image#830a61020d5af6e8

This patch is in trunk in the meantime.

If you really want automatic scaling, you'd have to do something like this:

import Image
from sphinx.builders.html import StandaloneHTMLBuilder

MAX_WIDTH = 600

def post_process_images(self, doctree):
    for node in doctree.traverse(nodes.image):
    if not (node.has_key('width') or node.has_key('height')):
        try:
            im = Image.open(os.path.join(self.srcdir, node['uri']))
        except (IOError, # Source image can't be found or opened
            UnicodeError):  # PIL doesn't like Unicode paths.
            pass
        else:
            if im.size[0] > MAX_WIDTH:
                node['scale'] = MAX_WIDTH / im.size[0]

    self._orig_post_process_images(doctree)

StandaloneHTMLBuilder._orig_post_process_images = \
    StandaloneHTMLBuilder.post_process_images
StandaloneHTMLBuilder.post_process_images = post_process_images


cheers,
Georg

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to