-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Saving images to stdout using some file formats does not write the image correctly #5657
Comments
Additional note: This bug only happens when saving to stdout. It does not seem to happen when saving to a named file, file object, or other file-like objects like BytesIO. Interestingly, some other file formats are affected as well: when saving the image as JPEG, no data is written at all. With GIF the image is corrupted (see below). PNG seems to be unaffected, though. GIF example: im = Image.frombytes('RGB', (4, 4), b'\xff\0\0' * 16)
im.save(sys.stdout, 'gif') The output has two black pixels (unexpected) in lower left. |
Most image formats have invalid utf-8 sequences in them, so they're not generally going to work with sys.stdout, unless you explicitly write the binary data to the underlying stream as mentioned in the link. |
Well, Pillow should be able to convert |
Missed that change. |
(note: this bug has implications "downstream" in Inkscape where we use pillow to convert to different formats on export : https://gitlab.com/inkscape/inkscape/-/issues/2860 - Proposed fix ("remove lines 496 to 502 in ImageFile.py") appears to solve it ) |
PNG is unaffected because it wraps |
What did you do?
I created a image and saved it to stdout using PPM format.
What did you expect to happen?
The image is written correctly.
What actually happened?
Only the PPM header is written, and the image data is not.
What are your OS, Python and Pillow versions?
The text was updated successfully, but these errors were encountered: