madam.image module

class madam.image.FlipOrientation(value)[source]

Bases: Enum

Represents an axis for image flip operations.

HORIZONTAL = 0

Horizontal axis

VERTICAL = 1

Vertical axis

class madam.image.PillowProcessor(config: Mapping[str, Any] | None = None)[source]

Bases: Processor

Represents a processor that uses Pillow as a backend.

__init__(config: Mapping[str, Any] | None = None) None[source]

Initializes a new PillowProcessor.

Parameters:

config – Mapping with settings.

auto_orient(asset: Asset) Asset[source]

Creates a new asset whose essence is rotated according to the Exif orientation. If no orientation metadata exists or asset is not rotated, an identical asset object is returned.

Parameters:

asset (Asset) – Asset with orientation metadata

Returns:

Asset with rotated essence

Return type:

Asset

can_read(file: IO) bool[source]

Returns whether the specified MIME type is supported by this processor.

Parameters:

file (IO) – file-like object to be tested

Returns:

whether the data format of the specified file is supported or not

Return type:

bool

convert(asset: Asset, mime_type: MimeType | str, color_space: str | None = None, depth: int | None = None, data_type: str | None = None) Asset[source]

Creates a new asset of the specified MIME type from the essence of the specified asset.

Parameters:
  • asset (Asset) – Asset whose contents will be converted

  • mime_type (MimeType or str) – Target MIME type

  • color_space (str or None) – Name of color space

  • depth (int or None) – Bit depth per channel

  • data_type (str or None) – Data type of the pixels, e.g. ‘uint’ or ‘float’

Returns:

New asset with converted essence

Return type:

Asset

crop(asset: Asset, x: int, y: int, width: int, height: int) Asset[source]

Creates a new asset whose essence is cropped to the specified rectangular area.

Parameters:
  • asset (Asset) – Asset whose contents will be cropped

  • x (int) – horizontal offset of the cropping area from left

  • y (int) – vertical offset of the cropping area from top

  • width (int) – width of the cropping area

  • height (int) – height of the cropping area

Returns:

New asset with cropped essence

Return type:

Asset

flip(asset: Asset, orientation: FlipOrientation) Asset[source]

Creates a new asset whose essence is flipped according the specified orientation.

Parameters:
  • asset (Asset) – Asset whose essence is to be flipped

  • orientation (FlipOrientation) – axis of the flip operation

Returns:

Asset with flipped essence

Return type:

Asset

read(file: IO) Asset[source]

Returns an Asset object whose essence is identical to the contents of the specified file.

Parameters:

file (IO) – file-like object to be read

Returns:

Asset with essence

Return type:

Asset

Raises:

UnsupportedFormatError – if the specified data format is not supported

resize(asset: Asset, width: int, height: int, mode: ResizeMode = ResizeMode.EXACT) Asset[source]

Creates a new Asset whose essence is resized according to the specified parameters.

Parameters:
  • asset (Asset) – Asset to be resized

  • width (int) – target width

  • height (int) – target height

  • mode (ResizeMode) – resize behavior

Returns:

Asset with resized essence

Return type:

Asset

rotate(asset: Asset, angle: float, expand: bool = False) Asset[source]

Creates an asset whose essence is rotated by the specified angle in degrees.

Parameters:
  • asset (Asset) – Asset whose contents will be rotated

  • angle (float) – Angle in degrees, counter clockwise

  • expand (bool) – If true, changes the dimensions of the new asset so it can hold the entire rotated essence, otherwise the dimensions of the original asset will be used.

Returns:

New asset with rotated essence

Return type:

Asset

transpose(asset: Asset) Asset[source]

Creates a new image asset whose essence is the transpose of the specified asset’s essence.

Parameters:

asset (Asset) – Image asset whose essence is to be transposed

Returns:

New image asset with transposed essence

Return type:

Asset

class madam.image.ResizeMode(value)[source]

Bases: Enum

Represents a behavior for image resize operations.

EXACT = 0

Image exactly matches the specified dimensions

FILL = 2

Image is resized to completely fill the specified dimensions

FIT = 1

Image is resized to fit completely into the specified dimensions