Skip to content

Since 10.0.1, saving an image as a JPEG does not always result in files of the same size #7477

@johnnyleitrim

Description

@johnnyleitrim

What did you do?

Using Pillow 10.0.1 and above, saving an image as a JPEG does not always result in the same number of bytes being written.

What did you expect to happen?

Saving the same image multiple times as a JPEG would result in files of the same size.

What actually happened?

The file sizes differ

What are your OS, Python and Pillow versions?

  • OS: macOS Ventura 13.6
  • Python: 3.9.6
  • Pillow: 10.0.1
from io import BytesIO

from PIL import Image

image = Image.new(mode="RGB", size=(1024, 1024), color="red")

for _ in range(10):
    output = BytesIO()
    image.save(output, format="jpeg")
    output.seek(0)
    print(len(output.read()))

Actual Output:

17013
17014
17014
17014
17014
17013
17013
17014
17014
17014

Expected output:

The number of bytes should be the same for each iteration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions