Installing Pillow
Pillow is the friendly, actively maintained fork of the original PIL (Python Imaging Library). It is the standard way to read, edit, and convert images in Python. Install it with pip:
pip install PillowOnce it is installed you import it as PIL in your code — for example from PIL import Image. Every example below uses that single import.
Convert PNG to JPG (RGB conversion)
JPG has no alpha channel, so you can't save a transparent PNG directly as a JPG. Convert the image to RGB first to flatten any transparency, then save with a quality setting:
from PIL import Image
img = Image.open("input.png").convert("RGB")
img.save("output.jpg", quality=90)The quality=90 argument keeps the image looking sharp while shrinking the file. Lower it for smaller files. For a one-off file without writing any code, you can convert PNG to JPG right in your browser.
Convert PNG to WebP
WebP supports transparency, so converting a PNG to WebP is even simpler — there is no RGB step to worry about. Pillow picks the format from the file extension:
from PIL import Image
Image.open("input.png").save("output.webp")The transparent background carries straight over. You can also add quality=80 to trade a little detail for a much smaller file. To do this without Python, try the browser tool to convert PNG to WebP.
Batch-convert a whole folder
The real strength of Pillow is automation. Loop over every PNG in a folder with glob and convert each one in a single pass:
from glob import glob
from PIL import Image
for path in glob("*.png"):
out = path.replace(".png", ".jpg")
Image.open(path).convert("RGB").save(out, quality=90)Swap the output extension to .webp (and drop the RGB conversion) to batch-convert to WebP instead. This pattern is ideal for build pipelines, cron jobs, and one-time bulk cleanups.
No-code alternative
Pillow is the right tool when you need repeatable, scripted conversions. For a single image — or if you would rather not install anything — a browser converter is simpler and instant. Browse the full set of conversion tools, or read what is a PNG to understand the format you're working with.
Frequently asked questions
- Why do I get an error saving a PNG as JPG in Pillow?
- JPG has no alpha channel, so Pillow raises an error when a PNG has transparency. Call .convert('RGB') before saving to flatten the image, and the JPG will save cleanly.
- Does converting PNG to WebP with Pillow keep transparency?
- Yes. WebP supports an alpha channel, so saving a PNG straight to .webp preserves the transparent background without any extra conversion step.
- How do I control JPG or WebP quality in Pillow?
- Pass a quality argument to save(), such as quality=90. Lower numbers give smaller files with more compression artifacts; higher numbers keep more detail at a larger size.
- Do I need Python to convert a single PNG?
- No. Pillow is ideal for automation and batch jobs, but for a one-off file a browser-based converter is faster and needs no setup.