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.
from PIL import Image
img = Image.open("eyes.jpg")
img.save("output.jpg")
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.
from PIL import Image
img = Image.open("eyes.png")
img.save("eyes2.jpg")
Output

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.
from PIL import Image
img = Image.open("flower.jpg")
img.save("compressed.jpg", quality=40)
Output

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.
from PIL import Image
img = Image.open("flower.jpg")
with open("saved_image.bin", "wb") as f:
img.save(f, format="JPEG")
Output

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