Pass BytesIO to PIL under Python 3

Inspiration for this fix taken from
https://github.com/python-imaging/Pillow/pull/341