Thursday, December 26, 2024
Google search engine
HomeLanguagesWand save() method in Python

Wand save() method in Python

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 :




# 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.

Parameter Input Type Description
file file object a file object to write to the file parameter
filename basestring a 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

Last Updated :
22 Apr, 2020
Like Article
Save Article

<!–

–>

Similar Reads
Related Tutorials
RELATED ARTICLES

Most Popular

Recent Comments