'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)
    if (self.config.html_scaled_image_link and self.html_scaled_image_link):
        for node in doctree.traverse(nodes.image):
            scale_keys = ('scale', 'width', 'height')
            if ((not any(((key in node) for key in scale_keys))) or isinstance(node.parent, nodes.reference)):
                continue
            uri = node['uri']
            reference = nodes.reference('', '', internal=True)
            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)
