mcfonts.render.formatting

Bonus functions to compliment rendering.

These functions are not used anywhere in the built-in rendering system, but were prototyped for a more advanced, "formatting-aware" system. That system was axed in favor of a more plain layout system, and these functions remain.

Implementors and developers are welcome to use any of these items, and while they should function generally, thye have not been extensively tested or checked for accuracy. Some may need to be re-written.

Warning

Most notably, shadow() and line() cannot both be applied correctly.

Module Contents

bold(image: PIL.Image.Image, offset: int = 1) PIL.Image.Image

Bold-ify an image by placing a copy of it offset pixels to the right.

If necessary, canvas is extended.

Parameters:
image : PIL.Image.Image

The image.

offset : int

Bold offset.

Returns:

A new image copy.

Return type:

PIL.Image.Image

color_as_rgb_255(color: str) tuple[int, int, int]

Transform a 6-digit hex color string into a tuple of its RGB values, out of 255.

Parameters:
color : str

Hex color without #, as in 45F9C2.

Returns:

Tuple of 3 numbers from 0-255.

Return type:

tuple[int, int, int]

color_int_as_rgb_255(color: int) tuple[int, int, int]

Transform a color as an integer into its components, out of 255.

Parameters:
color : int

Integer like 0x34FF9C.

Returns:

Tuple of integers like (52, 255, 156).

Return type:

tuple[int, int, int]

italic(image: PIL.Image.Image, angle_rad: float = radians(70)) tuple[PIL.Image.Image, int, int]

Italicize an image by shearing it.

Parameters:
image : PIL.Image.Image

The image.

angle_rad : float

Angle of shearing, in radians. Default is 70 degrees == 1.221.

Returns:

Tuple of image, additional left padding, additional right padding.

Return type:

tuple[PIL.Image.Image, int, int]

line(image: PIL.Image.Image, color: tuple[int, int, int], y: int, thickness: int = 1) PIL.Image.Image

Draw a horizontal bar across the image.

Parameters:
image : PIL.Image.Image

The image to draw on

color : tuple[int, int, int]

Color of the bar

y : int

Vertical position

thickness : int

Thickness of the bar in pixels

Returns:

Modified image copy

Return type:

PIL.Image.Image

shadow(image: PIL.Image.Image, color: int | None, offset: tuple[int, int], brightness_factor: float = SHADOW_BRIGHTNESS_FACTOR) PIL.Image.Image

Create a shadow on an image.

Parameters:
image : PIL.Image.Image

The image.

color : int | None

Color of the shadow.

offset : tuple[int, int]

Offset of the shadow, in (x, y).

brightness_factor : float

Brightness factor of the shadow, if color is None.

Returns:

Image with the shadow applied.

Return type:

PIL.Image.Image

DEFAULT_COLOR : Final[tuple[int, int, int]] = (255, 255, 255)
SHADOW_BRIGHTNESS_FACTOR : Final[float] = 0.25
SHADOW_OPACITY : Final[int] = 63