How to convert PNG to JPG in Python using the PIL library

You can convert PNG to JPG in Python using the PIL library. If you want to learn about computer vision, I strongly advise you to read This book.

Step 1:

Install the Pillow library.

pip install Pillow

Step 2:

Convert PNG to JPG in Python

# Import the required module
from PIL import Image

# Load the PNG image (The image should be in the same directory otherwise mention the location)
img = Image.open("baby.png")

# Convert into RGB
img = img.convert("RGB")

# Save the baby image as a JPG
img.save("baby.jpg")

Related Articles:

Leave a Comment

Your email address will not be published.