Python Pillow – Convert JPEG to PNG

Pillow – Convert image from JPEG to PNG format

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

Syntax of save() function

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


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 JPEG image to PNG

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

Python Program

from PIL import Image

# Open the image
jpg_image ="test_image.jpg")

# Save the image with PNG format"test_image.png", format="PNG")

Original Image [test_image.jpg]

Python Pillow - Convert image from JPEG to PNG Example - Output image

Resulting Image [test_image.png]

Python Pillow - Convert image from JPEG to PNG Example - Input image


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

Related Tutorials

Code copied to clipboard successfully 👍