Fixed crash on the following two cases:
Created originally on Bitbucket by luisbc92 (Luis Banuelos)
Changesets for this Pull Request have not been imported, because it had been already declined on Bitbucket. Marked as closed by the import user.
Fixed crash on the following two cases:
- If PIL Image format is set to None, an AttributeError is thrown when the format is stored in self.format as lowercase.
- If PIL Image was created in memory (such as with Image.fromarray), a file pointer is never created and an AttributeError is thrown when _data is called.
This fix consists of the following:
- Format is no longer read on initialization.
- On _data, if the image has a file pointer, and if the format is ['png', 'gif', 'jpeg'], the existing file pointer is rewinded to 0, and data is returned with fp.read(). If no file pointer exists, or format is incorrect, the image is saved into a BytesIO buffer, pointer is rewinded to 0, and data is returned with fp.read()