Revised for latest Python, Pillow.