1

The solutions I have found said to:

from PIL import Image
import io

img = "1.jpg"
image = Image.open(img)

# ... other processing...

buf = io.BytesIO()
image.save(buf, format="JPEG")
buf.get_value()

But I get the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: '_io.BytesIO' object has no attribute 'get_value'

If I try instead:

buf.seek(0)

It just outputs 0.

Those are the only two suggestions I have found and they are not working for me. Is it an issue with my versions? I have Python 3.7.3 and PIL 6.1.0

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
Lisa
  • 55
  • 1
  • 6
  • 1
    I'm doing some operations using PIL before saving it, but I left it out in this code to simplify the problem – Lisa Nov 13 '19 at 14:11

2 Answers2

3

Try:

>>> buf.seek(0) # Return to beginning of buffer
>>> data = buf.read() # Read all bytes until EOF
Seb
  • 4,422
  • 14
  • 23
2

The error says it all, BytesIO object has no attribute named get_value. The attribute is getvalue() and not get_value(). Refer the docs for more information https://docs.python.org/3/library/io.html#io.BytesIO

techytushar
  • 673
  • 5
  • 17