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

Do not prematurely return in ImageFile when saving to stdout #5665

Merged
merged 4 commits into from Nov 25, 2021

Conversation

infmagic2047
Copy link
Contributor

Fixes #5657.

The removed block of code is bad for the following reasons:

  1. The return statement makes the function write nothing when fp is stdout, which is obviously unwanted.
  2. The fp.flush() statement is duplicate of the line below, and is therefore useless.

@radarhere
Copy link
Member

When I try this, it doesn't fix the issue for me. Could you add a test to demonstrate?

@infmagic2047
Copy link
Contributor Author

Added tests for JPEG and PPM formats.

Tests/test_file_ppm.py Outdated Show resolved Hide resolved
Tests/test_file_jpeg.py Outdated Show resolved Hide resolved
@radarhere
Copy link
Member

This is reverting part of #1365. That PR added return to prevent the encoder writing bytes to sys.stdout.

Looking back now, I think that was incorrect for this reason, that it did prevent the body of the image from being output.

@radarhere radarhere changed the title Remove stdout check in ImageFile._save Do not return in ImageFile when saving to stdout Nov 25, 2021
@radarhere radarhere merged commit ab6efcb into python-pillow:main Nov 25, 2021
@radarhere radarhere changed the title Do not return in ImageFile when saving to stdout Do not prematurely return in ImageFile when saving to stdout Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saving images to stdout using some file formats does not write the image correctly
2 participants