'Draw a PIL image, centered in the given box.'

def image(self, box, im, dpi=None):

    if (not dpi):
        if (im.mode == '1'):
            dpi = 200
        else:
            dpi = 100
    x = (float((im.size[0] * 72)) / dpi)
    y = (float((im.size[1] * 72)) / dpi)
    xmax = float((box[2] - box[0]))
    ymax = float((box[3] - box[1]))
    if (x > xmax):
        y = ((y * xmax) / x)
        x = xmax
    if (y > ymax):
        x = ((x * ymax) / y)
        y = ymax
    dx = (((xmax - x) / 2) + box[0])
    dy = (((ymax - y) / 2) + box[1])
    self._fp_write(('gsave\n%f    %f    translate\n' % (dx, dy)))
    if ((x, y) != im.size):
        sx = (x / im.size[0])
        sy = (y / im.size[1])
        self._fp_write(('%f    %f    scale\n' % (sx, sy)))
    EpsImagePlugin._save(im, self.fp, None, 0)
    self._fp_write('\ngrestore\n')
