mcfonts.utils.image

Simple utilities for working with PIL.Image.Image.

Module Contents

Functions

get_image_bearings(image)

Return the two integers of the bearings of an image.

get_largest_effective_image_dimensions(images[, ...])

Given a list of images, return the width and height of the largest images in that list.

get_largest_image_dimensions(images[, isolate_dimensions])

Given a list of images, return the width and height of the largest image's canvas in that list.

is_image_empty(image)

Determine if image has any pixel data.

is_image_invisible(image)

Determine if image has all invisible pixels; if alpha is 0.

mcfonts.utils.image.get_image_bearings(image)

Return the two integers of the bearings of an image.

Bearings are a "padding" from the edge of the canvas to image pixels. Left bearing is the distance from the left edge of the canvas to the most-left pixel data. Right bearing is the distance from the right edge of the canvas to the most-right pixel data.

If return is (0, 0), there's no pixel data, the glyph is all spaces.

Parameters:
image : PIL.Image.Image

A PIL.Image.Image instance.

Returns:

Left bearing and right bearing. Returns (0, 0) if there's no pixel data.

Return type:

tuple[int, int]

mcfonts.utils.image.get_largest_effective_image_dimensions(images, isolate_dimensions=True)

Given a list of images, return the width and height of the largest images in that list.

This function operates based on the pixels inside an image; it crops out empty space and then determines the width and height. For a function that operates on an image's true width and height, see func:get_largest_image_dimensions.

Parameters:
images : list[PIL.Image.Image]

An iterable of the images to iterate over.

isolate_dimensions : bool

If True, the maximum height and width will be calculated. This means that dimensions (4, 6) (12, 8) (3, 9) will be (12, 9).

If False, the maximum height and width is dependent on the maximum width found. This means that dimensions (4, 6) (12, 8) (3, 9) will be (12, 8). It is recommended that you leave this to True.

Returns:

A tuple of (maximum width, maximum height).

Return type:

tuple[int, int]

mcfonts.utils.image.get_largest_image_dimensions(images, isolate_dimensions=True)

Given a list of images, return the width and height of the largest image's canvas in that list.

This function is different from func:get_largest_effective_image_dimensions in that it does not calculate the real width and height that pixels in an image extend to. It only relies on the width and height of the image's canvas (the total space).

Parameters:
images : collections.abc.Iterable[PIL.Image.Image | None]

A list of the glyphs to iterate over.

isolate_dimensions : bool

If True, the maximum height and width will be calculated separately. This means that dimensions (4, 6) (12, 8) (3, 9) will be (12, 9).

If False, the maximum height and width is dependent on the maximum width found. This means that dimensions (4, 6) (12, 8) (3, 9) will be (12, 8).

It is recommended that you leave this to True.

Returns:

A tuple of (maximum width, maximum height).

Return type:

tuple[int, int]

mcfonts.utils.image.is_image_empty(image)

Determine if image has any pixel data.

Parameters:
image : PIL.Image.Image

A PIL.Image.Image.

Returns:

If image has pixel data.

Return type:

bool

mcfonts.utils.image.is_image_invisible(image)

Determine if image has all invisible pixels; if alpha is 0.

Parameters:
image : PIL.Image.Image

A PIL.Image.Image.

Returns:

If image doesn't have any full-alpha pixels.

Return type:

bool


Last update: 2023 November 30