Frame, Image and Placement¶
These three objects are useful for animations or for image alignment within the Canvas
.
The most important thing to remember is:
That is, a Placement
contains a Image
which contains a Frame
. Once that’s all done, the Placement
can be placed on the Canvas
.
Frame¶
- class chafa.Frame(src_pixel_type: PixelType, src_pixels, src_width: int, src_height: int, src_rowstride: int)¶
This defines a frame of an image. This has to be added to an
Image
. The inputs are the same as inCanvas.draw_all_pixels()
.Note
Best performance is achieved by passing a
ctypes.Array
for src_pixels. A fast way to do this is to use Pillow; specifically the Image.tobytes method.- Parameters:
src_pixel_type (PixelType) – The pixel type of src_pixels. This will determine what order the color channels will be read in and whether there is an alpha channel.
src_pixels (list|tuple|array.array|ctypes.Array) – The source pixel data. This is a one dimensional array where every block of 3 (or 4 depending on the
PixelType
) values represents one pixel of the image. The order of the channels is determined by src_pixel_type.src_width (int) – The width of the source image.
src_height (int) – The width of the source image.
src_rowstride (int) – The number of values in src_image that represents one line pixels in the source image. Typically this will be the number of channels in the source image multiplied by src_width, e.g. for an image with no alpha channel and a width of 300 pixels, this will be
3*300
.
- Raises:
ValueError – if src_width, src_height or src_rowstride are less than or equal to 0.
Added in version 1.2.0.
Image¶
Placement¶
After assigning a Placement
to a Canvas
with Canvas.placement
, you can print the Canvas
using Canvas.print()
.
- class chafa.Placement(image: Image, id: int = 0)¶
This class defines the placement of an
Image
on aCanvas
.Note
None of placement’s properties have any effect if the
Canvas
’s pixel mode is set toPixelMode.CHAFA_PIXEL_MODE_SYMBOLS
.- Parameters:
image – The
Image
to be placed.id – An id to assign to the image. Leave as
0
to assign one automatically.
Added in version 1.2.0.
- property tuck¶
- Type:
This describes how the
Image
is resized to fit on theCanvas
, and defaults toTuck.CHAFA_TUCK_STRETCH
.