Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Wand save() method in Python

  • Last Updated : 22 Apr, 2020

Whenever we manipulate an image and want to preserve image for further image, we use save() function. save() function saves the image into the file or filename. It saves the final manipulated image in your disk.

Syntax :

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course




# image manipulation code
wand.image.save(file = file_object or 
                filename='filename.format')

Parameters :
It has only two parameter and takes only one at a time.



ParameterInput TypeDescription
filefile objecta file object to write to the file parameter
filenamebasestringa filename object to write to the file parameter

Now let’s see code to save image.

Example #1: Save image to the disk.




# import Image from wand.image module
from wand.image import Image
  
# read image using 
with Image(filename ='koala.png') as img:
    # manipulate image
    img.rotate(90 * r)
  
    # save final image after
    img.save(filename ='final.png')

Output :

In output an image named koala.png will be saved in disk

Example #2:

We can save image to output stream using save() function too. For example, the following code converts koala.png image into JPEG, gzips it, and then saves it to koala.jpg.gz:




# import gzip
import gzip
  
# import Image from wand.image module
from wand.image import Image
  
# create gz compressed file
gz = gzip.open('koala.jpg.gz')
  
# read image using Image() function
with Image(filename ='pikachu.png') as img:
    # get format of image
    img.format = 'jpeg'
  
    # save image to output stream using save() function
    img.save(file = gz)
gz.close()

Output :

A compressed file named koala.jpg.gz get saved in disk



My Personal Notes arrow_drop_up
Recommended Articles
Page :