Python PIL | Image.save() method

Last Updated : 23 Dec, 2025

The Image.save() method in PIL is used to store an image on disk in any supported format such as JPG, PNG, or BMP. It allows you to save an edited, resized, or newly created image using a filename or a file object. The format is usually detected from the file extension unless explicitly provided.

Note: We will be using a sample image "eyes.jpg", to download click here and make sure to keep the image in the same folder as your python script.

Example: This example loads an image and saves it with a new filename. It shows the use of the save() method.

Python
from PIL import Image
img = Image.open("eyes.jpg")
img.save("output.jpg")

Output

Output

Explanation: img.save("output.jpg") writes the image to a new file using the JPEG format (detected from .jpg).

Syntax

Image.save(fp, format=None, **params)

Parameters:

  • fp: filename or file object where the image will be saved.
  • format (Optional): format override (e.g., "PNG", "JPEG"). Needed when a file object is used.
  • params: Additional options such as quality, compression, etc., depending on the format.

Examples

Example 1: This example converts an image from JPG to PNG by simply changing the output file extension.

Python
from PIL import Image
img = Image.open("eyes.png")
img.save("eyes2.jpg")

Output

Output1
A new file eyes2.png is created.

Explanation: img.save("eyes2.png") automatically switches the image format to PNG based on the extension.

Example 2: This example saves the image with a lower JPEG quality to reduce file size.

Python
from PIL import Image
img = Image.open("flower.jpg")
img.save("compressed.jpg", quality=40)

Output

Output2
A new file compressed.jpg with reduced quality.

Explanation: quality=40 tells the JPEG writer to compress the image more, producing a smaller file.

Example 3: Saving an Image Using an Explicit Format when using a file object instead of a filename, the format must be explicitly provided.

Python
from PIL import Image
img = Image.open("flower.jpg")
with open("saved_image.bin", "wb") as f:
    img.save(f, format="JPEG")

Output

Screenshot-2025-12-23-124609
A new file saved_image.bin containing image data in JPEG format.

Explanation: img.save(f, format="JPEG") specifies the format manually because the file object has no extension.

Comment
Article Tags:

Explore