im1 = im.resize((tilesize, tilesize), Image.BILINEAR)
if os.path.exists(tilefilename):
    im0 = Image.open(tilefilename)
im1 = Image.composite(im1, im0, im1)
im1AsArray = numpy.array(im1)
alpha = im1AsArray[:, :, (3)]
semiTransparentIndices = alpha < 255
alpha[semiTransparentIndices] = 0
im1AsArray[:, :, (3)] = alpha
im1 = Image.fromarray(im1AsArray, 'RGBA')
im1.save(tilefilename, self.tiledriver)
Getting rid of thin border at edge with transparency when antialiasing with Python Image Library 