python - PIL cannot identify image file for io.BytesIO object -


i using pillow fork of pil , keep receiving error

oserror: cannot identify image file <_io.bytesio object @ 0x103a47468>

when trying open image. using virtualenv python 3.4 , no installation of pil.

i have tried find solution based on others encountering same problem, however, solutions did not work me. here code:

from pil import image import io  # portion part of test code byteimg = image.open("some/location/to/a/file/in/my/directories.png").tobytes()  # non test code databytesio = io.bytesio(byteimg) image.open(databytesio) # <- error here 

the image exists in initial opening of file , gets converted bytes. appears work else can't figure out why fails me.

edit:

databytesio.seek(0) 

does not work solution (tried it) since i'm not saving image via stream, i'm instantiating bytesio data, therefore (if i'm thinking of correctly) seek should @ 0.

(this solution author himself. have moved here.)

solution:

# portion part of test code byteimgio = io.bytesio() byteimg = image.open("some/location/to/a/file/in/my/directories.png") byteimg.save(byteimgio, "png") byteimgio.seek(0) byteimg = byteimgio.read()   # non test code databytesio = io.bytesio(byteimg) image.open(databytesio) 

the problem way image.tobytes()was returning byte object. appeared invalid data , 'encoding' couldn't other raw still appeared output wrong data since every byte appeared in format \xff\. however, saving bytes via bytesio , using .read() function read entire image gave correct bytes when needed later used.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

java - disabling a node without disable its children in javafx -