'Pick the best candidate for an image and link down-scaled images to
their high res version.'

def post_process_images(self, doctree):

    Builder.post_process_images(self, doctree)
    for node in doctree.traverse(nodes.image):
        if ((not node.has_key('scale')) or isinstance(node.parent, nodes.reference)):
            continue
        uri = node['uri']
        reference = nodes.reference()
        if (uri in self.images):
            reference['refuri'] = posixpath.join(self.imgpath, self.images[uri])
        else:
            reference['refuri'] = uri
        node.replace_self(reference)
        reference.append(node)
