Image Handling tcod.image
#
Libtcod functionality for handling images.
This module is generally seen as outdated. To load images you should typically use Pillow or imageio unless you need to use a feature exclusive to libtcod.
Python-tcod is unable to render pixels to consoles.
The best it can do with consoles is convert an image into semigraphics which can be shown on non-emulated terminals.
For true pixel-based rendering you’ll want to access the SDL rendering port at tcod.sdl.render
.
- class tcod.image.Image(width: int, height: int)[source]#
A libtcod image.
- blit(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: 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: Console, x: int, y: int, width: int, height: int, bg_blend: int) None [source]#
Blit onto a Console without scaling or rotation.
- Parameters:
- classmethod from_array(array: numpy.typing.ArrayLike) 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.
- classmethod from_file(path: str | PathLike[str]) Image [source]#
Return a new Image loaded from the given path.
New in version 16.0.
- 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:
- refresh_console(console: Console) None [source]#
Update an Image created with
libtcodpy.image_from_console
.The console used with this function should have the same width and height as the Console given to
libtcodpy.image_from_console
. The font width and height must also be the same as whenlibtcodpy.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 | PathLike[str]) None [source]#
Save the Image to a 32-bit .bmp or .png file.
- Parameters:
filename (Text) – File path to same this Image.
Changed in version 16.0: Added PathLike support.