abstract_api.image_processing.strategies package#

Subpackages#

Submodules#

Module contents#

class abstract_api.image_processing.strategies.Auto(*, height: int, **kwargs)[source]#

Bases: HeightMixin, WidthMixin, BaseStrategy

Use auto selected strategy.

The best strategy (portrait or landscape) will be selected according to its aspect ratio.

class abstract_api.image_processing.strategies.BaseStrategy[source]#

Bases: ABC

Base class for all image processing strategies.

json() dict[str, int | str][source]#

Returns a dict with strategy attributes to be used with requests.

class abstract_api.image_processing.strategies.Crop(scale: int | None = None, x: int | None = None, y: int | None = None, **kwargs)[source]#

Bases: HeightMixin, WidthMixin, CropModeMixin, BaseStrategy

Crop an image to a specified exact size.

The resulting cropped image can optionally be scaled by inclusion of a scale, which accepts a number representing the percentage by which the image should be scaled.

If you want to crop from a direction other than the default “center”, you can specify a crop_mode parameter, which can take one of the following gravity (or direction) values: n or t - North / Top nw or tl - North West / Top Left ne or tr - North East / Top Right w or l - West / Left c - Center - this is the default gravity or direction, and applied

when the crop_mode parameter is left out, or an invalid value is passed.

e or r - East / Right se or br - South East / Bottom Right sw or bl - South West / Bottom Left s or b - South / Bottom

You can also use CropMode enum to pass the crop_mode parameter.

If you would like to crop a custom area from an image, you can do so by specifying the rectangular region you wish to extract as x, y, width and height. Optionally, you can pass a scale parameter (as mentioned above), which must be a number representing the percentage by which you would like to scale the image.

json() dict[str, int | str][source]#

Returns a dict with strategy attributes to be used with requests.

property scale: int | None#

The percentage by which you would like to scale the image.

property x: int | None#

X position of the rectangular area to be cropped, if needed.

property y: int | None#

Y position of the rectangular area to be cropped, if needed.

class abstract_api.image_processing.strategies.Exact(*, height: int, **kwargs)[source]#

Bases: HeightMixin, WidthMixin, BaseStrategy

Resize to exact width and height.

Aspect ratio will not be maintained.

class abstract_api.image_processing.strategies.Fill(background: str | None = None, **kwargs)[source]#

Bases: HeightMixin, WidthMixin, BaseStrategy

Resize image to fit the specified bounds while preserving aspect ratio.

The optional background parameter allows you to specify a color which will be used to fill the unused portions of the specified bounds. The default background color is black.

property background: str | None#

The color to be used to fill the unused portions.

json() dict[str, int | str][source]#

Returns a dict with strategy attributes to be used with requests.

class abstract_api.image_processing.strategies.Fit(*, height: int, **kwargs)[source]#

Bases: HeightMixin, WidthMixin, CropModeMixin, BaseStrategy

Crop and resize the image to fit the desired width and height.

class abstract_api.image_processing.strategies.Landscape(*, width: int, **kwargs)[source]#

Bases: WidthMixin, BaseStrategy

Resize to exact width.

Height will be adjusted according to aspect ratio.

class abstract_api.image_processing.strategies.Portrait(*, height: int, **kwargs)[source]#

Bases: HeightMixin, BaseStrategy

Resize to exact height.

Width will be adjusted according to aspect ratio.

class abstract_api.image_processing.strategies.Square(size: int)[source]#

Bases: BaseStrategy

Crop image by its shorter dimension to make it a square.

Image is resized after cropping to the specified size.

json() dict[str, int | str][source]#

Returns a dict with strategy attributes to be used with requests.

property size: int#

Size to resize the cropped image to.