Skip to content

Can't save all extensions to BytesIO #9428

@CTimmerman

Description

@CTimmerman

Image

What did you do?

Try to automate testing all supported save formats.

What did you expect to happen?

Use the special needs of the specific extensions like BW of SGI only accepting mode L. (Why don't the plugins use Pillow to convert the mode themselves?)

What actually happened?

python -m doctest main.py
**********************************************************************
File "d:\code\image viewer\tk_image_viewer\main.py", line 1157, in main.test_save
Failed example:
    test_save()
Exception raised:
    Traceback (most recent call last):
      File "C:\Users\C\AppData\Local\Python\pythoncore-3.13-64\Lib\doctest.py", line 1398, in __run
        exec(compile(example.source, filename, "single",
        ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     compileflags, True), test.globs)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "<doctest main.test_save[0]>", line 1, in <module>
        test_save()
        ~~~~~~~~~^^
      File "d:\code\image viewer\tk_image_viewer\main.py", line 1163, in test_save
        im.save(out, format=ext)
        ~~~~~~~^^^^^^^^^^^^^^^^^
      File "D:\code\image viewer\tk_image_viewer\venv\Lib\site-packages\PIL\Image.py", line 2575, in save
        save_handler = SAVE[format.upper()]
                       ~~~~^^^^^^^^^^^^^^^^
    KeyError: '.APNG'
**********************************************************************
1 item had failures:
   1 of   1 in main.test_save
***Test Failed*** 1 failure.

What are your OS, Python and Pillow versions?

  • OS: Windows 11
  • Python: Python 3.13 (in active venv)
  • Pillow: 12.1.0
Please paste here the output of running:

python3 -m PIL.report 
--------------------------------------------------------------------
Pillow 12.1.0
Python 3.14.2 (tags/v3.14.2:df79316, Dec  5 2025, 17:18:21) [MSC v.1944 64 bit (AMD64)]
--------------------------------------------------------------------
Python executable is C:\Users\C\AppData\Local\Python\pythoncore-3.14-64\python.exe
System Python files loaded from C:\Users\C\AppData\Local\Python\pythoncore-3.14-64
--------------------------------------------------------------------
Python Pillow modules loaded from C:\Users\C\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\PIL
Binary Pillow modules loaded from C:\Users\C\AppData\Local\Python\pythoncore-3.14-64\Lib\site-packages\PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 12.1.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.14.1
--- LITTLECMS2 support ok, loaded 2.17
--- WEBP support ok, loaded 1.6.0
--- AVIF support ok, loaded 1.3.0
--- JPEG support ok, compiled for libjpeg-turbo 3.1.3
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.4
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1.zlib-ng, compiled for zlib-ng 2.3.2
--- LIBTIFF support ok, loaded 4.7.1
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------

python -m PIL.report 
--------------------------------------------------------------------
Pillow 12.1.0
Python 3.13.12 (tags/v3.13.12:1cbe481, Feb  3 2026, 18:22:25) [MSC v.1944 64 bit (AMD64)]
--------------------------------------------------------------------
Python executable is D:\code\image viewer\tk_image_viewer\venv\Scripts\python.exe
Environment Python files loaded from D:\code\image viewer\tk_image_viewer\venv
System Python files loaded from C:\Users\C\AppData\Local\Python\pythoncore-3.13-64
--------------------------------------------------------------------
Python Pillow modules loaded from D:\code\image viewer\tk_image_viewer\venv\Lib\site-packages\PIL
Binary Pillow modules loaded from D:\code\image viewer\tk_image_viewer\venv\Lib\site-packages\PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 12.1.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.14.1
--- LITTLECMS2 support ok, loaded 2.17
--- WEBP support ok, loaded 1.6.0
--- AVIF support ok, loaded 1.3.0
--- JPEG support ok, compiled for libjpeg-turbo 3.1.3
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.4
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1.zlib-ng, compiled for zlib-ng 2.3.2
--- LIBTIFF support ok, loaded 4.7.1
--- RAQM (Bidirectional Text) support ok, loaded 0.10.3, fribidi 1.0.13, harfbuzz 12.3.0
*** LIBIMAGEQUANT (Quantization method) support not installed
*** XCB (X protocol) support not installed
--------------------------------------------------------------------

#TIL venv doesn't override "python3" as command. Sad.
from io import BytesIO
from PIL import Image

im = Image.open("eye.gif")
out = BytesIO()
for ext in ("APNG", "BW"):
        im.save(out, ext)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions