Python PIL | Image.save() method

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images.

Image.save() Saves this image under the given filename. If no format is specified, the format to use is determined from the filename extension, if possible.



Keyword options can be used to provide additional instructions to the writer. If a writer doesn’t recognise an option, it is silently ignored. The available options are described in the image format documentation for each writer.

You can use a file object instead of a filename. In this case, you must always specify the format. The file object must implement the seek, tell, and write methods, and be opened in binary mode.

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

Parameters:

fp – A filename (string), pathlib.Path object or file object.
format – Optional format override. If omitted, the format to use is determined from the filename extension. If a file object was used instead of a filename, this parameter should always be used.
options – Extra parameters to the image writer.

Returns: None

Raises:

KeyError – If the output format could not be determined from the file name. Use the format option to solve this.
IOError – If the file could not be written. The file may have been created, and may contain partial data.

Image Used:

filter_none

edit
close

play_arrow

link
brightness_4
code

   
  
# Importing Image module from PIL package 
from PIL import Image 
import PIL 
  
# creating a image object (main image) 
im1 = Image.open(r"C:\Users\System-Pc\Desktop\flower1.jpg"
  
# save a image using extension
im1 = im1.save("geeks.jpg")

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.