def make_transparent(img, bg=(255, 255, 255, 255)):
    """Given a PIL image, makes the specified background color transparent."""
    img = img.convert("RGBA")
    clear = bg[0:3]+(0,)
    pixdata = img.load()

    width, height = img.size
    for y in range(height):
        for x in range(width):
            if pixdata[x,y] == bg:
                pixdata[x,y] = clear
    return img