Skip to content

Saving image to buffer does not overwrite? #9452

@Spartanjackwar

Description

@Spartanjackwar

What did you do?

https://upload.wikimedia.org/wikipedia/commons/3/39/Oatmeal.jpg
Using the above linked image, I did the following within an IDLE session:

>>> from PIL import Image, ImageOps
>>> import io, os
>>> size = (100,100)
>>> img = Image.open("C:/Oatmeal.jpg")
>>> temp = ImageOps.contain(img, size)
>>> temp.show()
>>> buff = io.BytesIO()
>>> temp.save(buff, format='jpeg', quality=100, subsampling=0)
>>> wranglebuff = Image.open(buff)
>>> wranglebuff.show()
>>> temp.save(buff, format='png')
>>> wranglebuff = Image.open(buff)
>>> wranglebuff.show()

What did you expect to happen?

I expected the second show() in the buffer to be different (higher quality) than the first show() of the buffer.

What actually happened?

Both buffer show() invocations show the exact same image. It is possible that calling save() to the same in-memory object twice will continuously append to the stream as opposed to overwriting.

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.9.0
  • Pillow: 11.3.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions