updated to work with Pillow instead of PIL