mcfonts.image
Utilities for working with Image.
Module Contents
-
alpha_paste(first: PIL.Image.Image, second: PIL.Image.Image, offset: tuple[int, int], mask: PIL.Image.Image | None =
None) → PIL.Image.Image
- Parameters:
- first : PIL.Image.Image
-
- second : PIL.Image.Image
-
- offset : tuple[int, int]
-
- mask : PIL.Image.Image | None
-
- Return type:
PIL.Image.Image
-
alpha_paste_reversed(first: PIL.Image.Image, second: PIL.Image.Image, offset: tuple[int, int], mask: PIL.Image.Image | None =
None) → PIL.Image.Image
- Parameters:
- first : PIL.Image.Image
-
- second : PIL.Image.Image
-
- offset : tuple[int, int]
-
- mask : PIL.Image.Image | None
-
- Return type:
PIL.Image.Image
-
canvas_extend(image: PIL.Image.Image, *, left: int =
0, up: int = 0, right: int = 0, down: int = 0) → PIL.Image.Image
Extend the canvas of an image by adding transparent space in specified directions.
- Parameters:
- image : PIL.Image.Image
The source image.
- left : int
Number of pixels to extend on the left.
- up : int
Number of pixels to extend upward.
- right : int
Number of pixels to extend on the right.
- down : int
Number of pixels to extend downward.
- Returns:
New image with extended canvas.
- Return type:
PIL.Image.Image
-
get_optimal_mode(image: PIL.Image.Image, /) → str
Determine the best mode for an image.
This is done trying to "downgrade" the mode of the image as much as possible.
For example, if in RGB, check if we can downgrade to L.
If in L, check if it can downgrade to 1.
If in RGBA, check if it can downgrade to LA.
Possible returned modes:
- Parameters:
- image : PIL.Image.Image
The image.
- Returns:
Mode that would best store the pixel contents of image.
- Return type:
str
-
get_unique_colors(image: PIL.Image.Image, /) → set[int]
Return a set of the unique colors in this image.
Red, green, blue channels are packed into 1 integer. Alpha is ignored.
- Parameters:
- image : PIL.Image.Image
The image.
- Returns:
Set of unique color values.
- Return type:
set[int]
-
is_greyscale(image: PIL.Image.Image, /) → bool
Return if an image's RGB values are all equal for all pixels.
- Parameters:
- image : PIL.Image.Image
The image.
- Returns:
If image is greyscale.
- Return type:
bool
-
is_image_empty(image: PIL.Image.Image) → bool
Determine if image has any pixel data.
- Parameters:
- image : PIL.Image.Image
The image.
- Returns:
If image has pixel data.
- Return type:
bool
-
iterate_all_pixels(image: PIL.Image.Image, /) → collections.abc.Generator[tuple[int, int, int, int]]
Iterate over all pixels of a given RGBA image, yielding their values.
Pixel values are a list of values from each band.
- Parameters:
- image : PIL.Image.Image
The image.
- Returns:
A generator yielding the pixel values of the image.
- Return type:
collections.abc.Generator[tuple[int, int, int, int]]
-
iterate_band_pixels(image: PIL.Image.Image, /, band: int =
0) → collections.abc.Generator[int]
Iterate over the pixel values of a specific band in an image.
This function extracts pixel data for a given band from an image object and iterates through
these values. The band refers to a specific color channel or layer of the image.
- Parameters:
- image : PIL.Image.Image
The image.
- band : int
The index of the band (color channel) to iterate over.
- Returns:
A generator yielding pixel values for the specified band.
- Return type:
collections.abc.Generator[int]
-
needs_alpha(image: PIL.Image.Image, /) → bool
Return if an image needs an alpha channel.
- Parameters:
- image : PIL.Image.Image
The image.
- Returns:
If an alpha channel is necessary.
- Return type:
bool
-
with_color(image: PIL.Image.Image, rgb: tuple[int, int, int]) → PIL.Image.Image
- Parameters:
- image : PIL.Image.Image
-
- rgb : tuple[int, int, int]
-
- Return type:
PIL.Image.Image