'Generate a color for a given word using a fixed image.'

def __call__(self, word, font_size, font_path, position, orientation, **kwargs):

    font = ImageFont.truetype(font_path, font_size)
    transposed_font = ImageFont.TransposedFont(font, orientation=orientation)
    box_size = transposed_font.getsize(word)
    x = position[0]
    y = position[1]
    patch = self.image[x:(x + box_size[0]), y:(y + box_size[1])]
    if (patch.ndim == 3):
        patch = patch[:, :, :3]
    if (patch.ndim == 2):
        raise NotImplementedError('Gray-scale    images    TODO')
    color = np.mean(patch.reshape((-1), 3), axis=0)
    return ('rgb(%d,    %d,    %d)' % tuple(color))
