abstract_api.image_processing package#

Subpackages#

Submodules#

Module contents#

class abstract_api.image_processing.ImageProcessing(api_key: str | None = None)[source]#

Bases: BaseService[ImageProcessingResponse]

AbstractAPI image processing service.

Used to convert, compress, or optimize an image.

Attributes:

_subdomain: Image processing service subdomain.

upload(image: BinaryIO, lossy: bool | None = None, quality: int | None = None, resize: BaseStrategy | None = None) ImageProcessingResponse[source]#

Converts, compresses, or optimizes an image.

Args:
image: The image to be processed, it should be a file-like or a

file opened in binary reading mode.

lossy: If True, the API will perform a lossy compression on the

image, reducing the size massively with a small drop in image quality. If False, the image size will only be reduced slightly (10% - 20% at most), but there will be no reduction in image quality. The default value is False if this is not provided.

quality: This is an integer between 0 and 100 that determines

the quality level for lossy compression. If not submitted it will be determined intelligently by AbstractAPI. Generally a quality above 95 is useless and may result in an image that is larger than the input image, and a quality below 25 will result in an image so low in quality that it will be useless.

resize: This is an instance of BaseStrategy subclasses that

specifies how to resize the image. If not provided, we will only compress the image as desired.

Returns:

ImageProcessingResponse representing API call response.

url(url: str, lossy: bool | None = None, quality: int | None = None, resize: BaseStrategy | None = None) ImageProcessingResponse[source]#

Converts, compresses, or optimizes an image in the given URL.

Args:
url: The URL of the image that you would like to edit.

Note that is cannot be more than 32 MB in size.

lossy: If True, the API will perform a lossy compression on the

image, reducing the size massively with a small drop in image quality. If False, the image size will only be reduced slightly (10% - 20% at most), but there will be no reduction in image quality. The default value is False if this is not provided.

quality: This is an integer between 0 and 100 that determines

the quality level for lossy compression. If not submitted it will be determined intelligently by AbstractAPI. Generally a quality above 95 is useless and may result in an image that is larger than the input image, and a quality below 25 will result in an image so low in quality that it will be useless.

resize: This is an instance of BaseStrategy subclasses that

specifies how to resize the image. If not provided, we will only compress the image as desired.

Returns:

ImageProcessingResponse representing API call response.

class abstract_api.image_processing.ImageProcessingResponse(response: Response)[source]#

Bases: JSONResponse

Image processing service response.

property bytes_saved: int | None#

The number of bytes saved by optimizing the image, in bytes.

property final_height: int | None#

The final height of the processed image, in bytes.

property final_size: int | None#

The final size of the processed image, in bytes.

property final_width: int | None#

The final width of the processed image, in bytes.

property original_height: int | None#

The original height of the provided image, in bytes.

property original_size: int | None#

The original size of the provided image, in bytes.

property original_width: int | None#

The original width of the provided image, in bytes.

property url: str | None#

The URL with the new processed image.