Home / Errors / rgba-as-jpeg

Cannot write mode RGBA as JPEG

JPEG has no alpha channel, so a transparent image cannot be saved as one. Convert to RGB first and decide what fills the transparent areas.

OSError: cannot write mode RGBA as JPEG

The quick fix

im.convert("RGB").save("out.jpg")

This works, but it puts black behind anything transparent, which is rarely what you want.

The fix you probably want

from PIL import Image

im = Image.open("logo.png").convert("RGBA")
flat = Image.new("RGB", im.size, "white")
flat.paste(im, mask=im.split()[3])
flat.save("logo.jpg", quality=88)

A white background, with the alpha channel used as the mask so the edges blend properly instead of turning into a ragged outline.

Why this happens at all

JPEG stores three channels and has no concept of transparency. PNG screenshots, logos and anything with rounded corners arrive as RGBA, and the error appears the moment you try to save one with a .jpg name.

The same error with P and LA

Palette images with transparency and greyscale with alpha fail the same way. convert("RGB") handles both, and the paste trick above works for them too once you have converted to RGBA.

Or just keep the transparency

If you do not specifically need JPEG, save as PNG or WEBP and the problem disappears. WEBP supports alpha and is usually smaller than both. The converter shows the size difference on your own files.

Still stuck

The PIL to Pillow converter finds most of these automatically, and the other error pages cover the rest.