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 codewand.image.save(file=file_objectorfilename='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 modulefromwand.imageimportImage# read image usingwith Image(filename='koala.png') as img:# manipulate imageimg.rotate(90*r)# save final image afterimg.save(filename='final.png')Output :
In output an image named koala.png will be saved in diskExample #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 gzipimportgzip# import Image from wand.image modulefromwand.imageimportImage# create gz compressed filegz=gzip.open('koala.jpg.gz')# read image using Image() functionwith Image(filename='pikachu.png') as img:# get format of imageimg.format='jpeg'# save image to output stream using save() functionimg.save(file=gz)gz.close()Output :
A compressed file named koala.jpg.gz get saved in diskWriting code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Please Login to comment...


