ImageLoader¶
- class toasty.image.ImageLoader[source]¶
Bases:
object
A class defining how to load an image.
This is implemented as its own class since there can be some options involved, and we want to provide a centralized place for handling them all.
Attributes Summary
Methods Summary
add_arguments
(parser)Add standard image-loading options to an argparse parser object.
create_from_args
(settings)Process standard image-loading options to create an
ImageLoader
.load_path
(path)Load an image into memory from a filesystem path.
load_pil
(pil_img)Load an already opened PIL image.
load_stream
(stream)Load an image into memory from a file-like stream.
Attributes Documentation
- black_to_transparent = False¶
- colorspace_processing = 'srgb'¶
- crop = None¶
- psd_single_layer = None¶
Methods Documentation
- classmethod add_arguments(parser)[source]¶
Add standard image-loading options to an argparse parser object.
- Parameters:
- parser
argparse.ArgumentParser
The argument parser to modify
- parser
- Returns:
- The
ImageLoader
class (for chainability).
- The
Notes
If you are writing a command-line interface that takes a single image as an input, use this function to wire in to standardized image-loading infrastructure and options.
- classmethod create_from_args(settings)[source]¶
Process standard image-loading options to create an
ImageLoader
.- Parameters:
- settings
argparse.Namespace
Settings from processing command-line arguments
- settings
- Returns:
- A new
ImageLoader
initialized with the settings.
- A new
- load_path(path)[source]¶
Load an image into memory from a filesystem path.
- Parameters:
- pathstr
The filesystem path to load.
- Returns:
- A new
Image
.
- A new
- load_pil(pil_img)[source]¶
Load an already opened PIL image.
- Parameters:
- pil_img
PIL.Image.Image
The image.
- pil_img
- Returns:
- A new
Image
.
- A new
Notes
This function should be used instead of
Image.from_pil()
because may postprocess the image in various ways, depending on the loader configuration.