Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I close an image opened in Pillow?

I have a python file with the Pillow library imported. I can open an image with

Image.open(test.png) 

But how do I close that image? I'm not using Pillow to edit the image, just to show the image and allow the user to choose to save it or delete it.

like image 412
Chase Cromwell Avatar asked Jul 31 '15 17:07

Chase Cromwell


People also ask

How do I close an image?

You can also use the keyboard shortcut, Ctrl+W (Win) / Command+W (Mac): To close a single image, go to File > Close.

How do you reshape a picture on a pillow?

The Image module from pillow library has an attribute size. This tuple consists of width and height of the image as its elements. To resize an image, you call the resize() method of pillow's image class by giving width and height.


1 Answers

With Image.close().

You can also do it in a with block:

with Image.open('test.png') as test_image:     do_things(test_image) 

An example of using Image.close():

test = Image.open('test.png') test.close() 
like image 197
Morgan Thrapp Avatar answered Sep 21 '22 08:09

Morgan Thrapp