August 2018
Intermediate to advanced
366 pages
10h 14m
English
There are four core parts of the ImageReader class that work together to provide support for reading image sizes.
The first, the ImageReader.get_size method itself, is in charge of opening the image file and detecting the image type.
The first part is all related to opening the file in case it's provided as a path in a string, as a Path object, or if it's already a file object:
requires_close = False
if isinstance(f, (str, getattr(os, 'PathLike', str))):
f = open(f, 'rb')
requires_close = True
elif isinstance(f, Path):
f = f.expanduser().open('rb')
requires_close = True
If it's a string or a pathlike object (os.PathLike is only supported on Python 3.6+), the file is opened and the requires_close variable is set to True, so ...