Fix image type detection in PIL.