Pillow save to BytesIO raises "ValueError: unknown file extension: " without format=
@shreyanshsaurabh01▲ -1 net votes
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.