tcod.image - Image Handling¶
Functionality for handling images.
Python-tcod is unable to render pixels to the screen directly. If your image can’t be represented as tiles then you’ll need to use an alternative library for graphics rendering.
-
class
tcod.image.
Image
(width: int, height: int)[source]¶ Parameters: -
blit
(console: tcod.console.Console, x: float, y: float, bg_blend: int, scale_x: float, scale_y: float, angle: float) → None[source]¶ Blit onto a Console using scaling and rotation.
Parameters: - console (Console) – Blit destination Console.
- x (float) – Console X position for the center of the Image blit.
- y (float) – Console Y position for the center of the Image blit. The Image blit is centered on this position.
- bg_blend (int) – Background blending mode to use.
- scale_x (float) – Scaling along Image x axis. Set to 1 for no scaling. Must be over 0.
- scale_y (float) – Scaling along Image y axis. Set to 1 for no scaling. Must be over 0.
- angle (float) – Rotation angle in radians. (Clockwise?)
-
blit_2x
(console: tcod.console.Console, dest_x: int, dest_y: int, img_x: int = 0, img_y: int = 0, img_width: int = -1, img_height: int = -1) → None[source]¶ Blit onto a Console with double resolution.
Parameters: - console (Console) – Blit destination Console.
- dest_x (int) – Console tile X position starting from the left at 0.
- dest_y (int) – Console tile Y position starting from the top at 0.
- img_x (int) – Left corner pixel of the Image to blit
- img_y (int) – Top corner pixel of the Image to blit
- img_width (int) – Width of the Image to blit. Use -1 for the full Image width.
- img_height (int) – Height of the Image to blit. Use -1 for the full Image height.
-
blit_rect
(console: tcod.console.Console, x: int, y: int, width: int, height: int, bg_blend: int) → None[source]¶ Blit onto a Console without scaling or rotation.
Parameters:
-
clear
(color: Tuple[int, int, int]) → None[source]¶ Fill this entire Image with color.
Parameters: color (Union[Tuple[int, int, int], Sequence[int]]) – An (r, g, b) sequence or Color instance.
-
classmethod
from_array
(array: Any) → tcod.image.Image[source]¶ Create a new Image from a copy of an array-like object.
Example
>>> import numpy as np >>> import tcod >>> array = np.zeros((5, 5, 3), dtype=np.uint8) >>> image = tcod.image.Image.from_array(array)
New in version 11.4.
-
get_alpha
(x: int, y: int) → int[source]¶ Get the Image alpha of the pixel at x, y.
Parameters: Returns: The alpha value of the pixel. With 0 being fully transparent and 255 being fully opaque.
Return type:
-
get_mipmap_pixel
(left: float, top: float, right: float, bottom: float) → Tuple[int, int, int][source]¶ Get the average color of a rectangle in this Image.
Parameters should stay within the following limits: * 0 <= left < right < Image.width * 0 <= top < bottom < Image.height
Parameters: Returns: An (r, g, b) tuple containing the averaged color value. Values are in a 0 to 255 range.
Return type:
-
get_pixel
(x: int, y: int) → Tuple[int, int, int][source]¶ Get the color of a pixel in this Image.
Parameters: Returns: An (r, g, b) tuple containing the pixels color value. Values are in a 0 to 255 range.
Return type:
-
put_pixel
(x: int, y: int, color: Tuple[int, int, int]) → None[source]¶ Change a pixel on this Image.
Parameters:
-
refresh_console
(console: tcod.console.Console) → None[source]¶ Update an Image created with
tcod.image_from_console
.The console used with this function should have the same width and height as the Console given to
tcod.image_from_console
. The font width and height must also be the same as whentcod.image_from_console
was called.Parameters: console (Console) – A Console with a pixel width and height matching this Image.
-
rotate90
(rotations: int = 1) → None[source]¶ Rotate this Image clockwise in 90 degree steps.
Parameters: rotations (int) – Number of 90 degree clockwise rotations.
-
save_as
(filename: str) → None[source]¶ Save the Image to a 32-bit .bmp or .png file.
Parameters: filename (Text) – File path to same this Image.
-
scale
(width: int, height: int) → None[source]¶ Scale this Image to the new width and height.
Parameters:
-