Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image.open() seeks to the start of file objects #7097

Merged
merged 1 commit into from Jun 29, 2023

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Apr 17, 2023

Resolves #7096 by documenting that Image.open() seeks to the start of file objects before reading.

Pillow/src/PIL/Image.py

Lines 3202 to 3225 in aec7a8d

try:
fp.seek(0)
except (AttributeError, io.UnsupportedOperation):
fp = io.BytesIO(fp.read())
exclusive_fp = True
prefix = fp.read(16)
preinit()
accept_warnings = []
def _open_core(fp, filename, prefix, formats):
for i in formats:
i = i.upper()
if i not in OPEN:
init()
try:
factory, accept = OPEN[i]
result = not accept or accept(prefix)
if type(result) in [str, bytes]:
accept_warnings.append(result)
elif result:
fp.seek(0)

@hugovk hugovk merged commit 1174a9e into python-pillow:main Jun 29, 2023
59 checks passed
@radarhere radarhere deleted the seek branch June 29, 2023 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot parse inline stream images, because open() always seeks 0
2 participants