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

black_to_transparent

colorspace_processing

crop

psd_single_layer

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
parserargparse.ArgumentParser

The argument parser to modify

Returns
The ImageLoader class (for chainability).

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
settingsargparse.Namespace

Settings from processing command-line arguments

Returns
A new ImageLoader initialized with the settings.
load_path(path)[source]

Load an image into memory from a filesystem path.

Parameters
pathstr

The filesystem path to load.

Returns
A new Image.
load_pil(pil_img)[source]

Load an already opened PIL image.

Parameters
pil_imgPIL.Image.Image

The image.

Returns
A new Image.

Notes

This function should be used instead of Image.from_pil() because may postprocess the image in various ways, depending on the loader configuration.

load_stream(stream)[source]

Load an image into memory from a file-like stream.

Parameters
streamfile-like

The data to load. Reads should yield bytes.

Returns
A new Image.