After looking at the source of the PIL.Image.show(...)
method, the method seems to write the image temporarily to disk (as the documentation stated) and then is immediately erased after it has been opened with an image viewer.
For example, the method for macOS is:
def show_file(self, file, **options):
"""Display given file"""
fd, path = tempfile.mkstemp()
with os.fdopen(fd, "w") as f:
f.write(file)
with open(path, "r") as f:
subprocess.Popen(
["im=$(cat); open -a Preview.app $im; sleep 20; rm -f $im"],
shell=True,
stdin=f,
)
os.remove(path)
return 1
This uses the tempfile.mkstemp([suffix=''[, prefix='tmp'[, dir=None[, text=False]]]])
method to create a temporary file. The documentation states:
If dir
is specified, the file will be created in that directory; otherwise, a default directory is used. The default directory is chosen from a platform-dependent list, but the user of the application can control the directory location by setting the TMPDIR, TEMP or TMP environment variables.
As no dir
is specified, the default directory used, which is selected like so: (stated here):
When set to a value other than None, this variable defines the default value for the dir argument to all the functions defined in this module.
If tempdir is unset or None at any call to any of the above functions, Python searches a standard list of directories and sets tempdir to the first one which the calling user can create files in. The list is:
- The directory named by the
TMPDIR
environment variable.
- The directory named by the
TEMP
environment variable.
- The directory named by the
TMP
environment variable.
- A platform-specific location:
- On RiscOS, the directory named by the
Wimp$ScrapDir
environment variable.
- On Windows, the directories
C:\TEMP
, C:\TMP
, \TEMP
, and \TMP
, in that order.
- On all other platforms, the directories
/tmp
, /var/tmp
, and /usr/tmp
, in that order.
- As a last resort, the current working directory.