Python Pillow – Convert PNG to JPEG

Pillow – Convert image from PNG to JPEG format

To convert an image from PNG format to JPEG format using Pillow library, first read the given PNG image to a PIL.Image.Image object and then save this image object using function with "JPEG" value passed for format parameter.

Syntax of save() function

The syntax of save() function from PIL.Image module to convert from PNG to JPEG format is, format="JPEG")


filepathA filename (string), pathlib.Path object or file object. The location to which this image has to be saved.


The function returns a PIL.Image.Image object.


1. Convert format of given PNG image to JPEG

In the following example, we read an image test_image.png with PNG format into an Image object. Then, we save this image object with JPEG format using function with file name test_image.jpg.

Python Program

from PIL import Image

# Open the image
png_image ="test_image.png")

# Save the image with JPEG format"test_image.jpg", format="JPEG")

Original Image [test_image.png]

Python Pillow - Convert PNG to JPG - Example input

Resulting Image [test_image.jpg]

Python Pillow - Convert PNG to JPG - Example output


In this Python Pillow Tutorial, we learned how to convert a given image with PNG format to a JPEG format image using function, with the help of examples.

Related Tutorials

Code copied to clipboard successfully 👍