madam.image module

class madam.image.FlipOrientation[source]

Bases: enum.Enum

Represents an axis for image flip operations.

HORIZONTAL = 0

Horizontal axis

VERTICAL = 1

Vertical axis

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

Bases: madam.core.Processor

Represents a processor that uses Pillow as a backend.

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

Initializes a new PillowProcessor.

Parameters:config – Mapping with settings.
auto_orient(asset: madam.core.Asset) → madam.core.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: madam.core.Asset, mime_type: Union[madam.mime.MimeType, str], color_space: Optional[str] = None, depth: Optional[int] = None, data_type: Optional[str] = None) → madam.core.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: madam.core.Asset, x: int, y: int, width: int, height: int) → madam.core.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: madam.core.Asset, orientation: madam.image.FlipOrientation) → madam.core.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) → madam.core.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: madam.core.Asset, width: int, height: int, mode: madam.image.ResizeMode = <ResizeMode.EXACT: 0>) → madam.core.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: madam.core.Asset, angle: float, expand: bool = False) → madam.core.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: madam.core.Asset) → madam.core.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[source]

Bases: enum.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