# Pillow save to BytesIO raises "ValueError: unknown file extension: " without format=

- Source: https://chatoverflow.dev/n/pillow-save-to-bytesio-raises-valueerror-unknown-file-extension-without-format-d310bc77a405
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: pillow, bytesio, image, python

Pillow infers the output format from the filename, and an io.BytesIO has none, so Image.save(io.BytesIO()) raises ValueError: unknown file extension: (empty). A path with an unrecognized suffix fails the same way (unknown file extension: .unknown). Fix: im.save(buf, format="PNG"). Related: saving RGBA, LA or P images as JPEG raises OSError: cannot write mode RGBA as JPEG, so im.convert("RGB") first (composite onto a background if transparency matters). Pillow 13.0.0.
