image_item

class janim.items.image_item.ImageItem(file_path_or_image: str | Image, *, width: float | None = None, height: float | None = None, min_mag_filter: tuple[int, int] = (9987, 9729), **kwargs)

Bases: Points

Image item

Reads the image from the given file path

renderer_cls

alias of ImageItemRenderer

image
color
apply_style(color: JAnimColor | ColorArray | None = None, alpha: Alpha | AlphaArray | None = None, **kwargs) Self

Set the item’s own style, does not affect child items

See also: set()

get_orig() ndarray

Top-left corner of the image

get_horizontal_vect() ndarray

Vector from the top-left corner to the top-right corner of the image

get_horizontal_dist() float

Length of get_horizontal_vect()

get_vertical_vect() ndarray

Vector from the top-left corner to the bottom-left corner of the image

get_vertical_dist() float

Length of get_vertical_vect()

pixel_to_rgba(x: int, y: int) ndarray

Get color based on pixel coordinates

point_to_rgba(point: ndarray, clamp_to_edge: bool = False) ndarray

Get the corresponding pixel color through spatial coordinates

pixel_to_point(x: float, y: float) ndarray

Get the corresponding spatial coordinates through pixel coordinates, can pass floating-point values

  • For example, .pixel_to_point(0, 0) returns the origin position (top-left corner of the image)

  • For example, .pixel_to_point(6, 11) returns the top-left corner of pixel (6, 11)

  • For example, .pixel_to_point(6.5, 11.5) returns the center of pixel (6, 11)

point_to_pixel(point: ndarray) tuple[int, int]

Get pixel coordinates based on spatial coordinates (rounded toward the image origin)

classmethod align_for_interpolate(item1: ImageItem, item2: ImageItem) AlignedData[ImageItem]

Perform data alignment for interpolation

class janim.items.image_item.PixelImageItem(file_path: str, *, width: float | None = None, height: float | None = None, min_mag_filter: tuple[int, int] = (9987, 9728), **kwargs)

Bases: ImageItem

Image item

Basically the same as ImageItem, except that when the image is enlarged for display, no smooth interpolation is performed, making pixels clear

class janim.items.image_item.VideoFrame(file_path: str, frame_at: str | float, *, width: float | None = None, height: float | None = None, **kwargs)

Bases: ImageItem

Video frame, used to extract a single frame image from the video at a specified time

  • file_path: File path

  • frame_at: Which frame to extract, can use seconds or ffmpeg-supported time formats, e.g., 17.4, '00:01:12', etc.

It is not recommended to use this class to extract multiple frames from a video for the purpose of “reading video”, as this will cause significant performance waste and memory usage

For playing video, use Video

static capture(file_path: str, frame_at: str | float, *, cache: bool = True) Image
class janim.items.image_item.Video(file_path: str, *, width: float | None = None, height: float | None = None, min_mag_filter: tuple[int, int] = (9987, 9729), frame_components: int = 3, **kwargs)

Bases: PlaybackControl, Points

Video item, similar to image items, essentially an image with real-time changing content

Methods for controlling video playback:

  • Like other items, use show() to display, paused on the first frame by default

  • Call start to begin playback from the current position, can pass a speed parameter to specify playback speed

  • Call stop to pause at the current position

  • Call seek to jump the video progress to a specified number of seconds

Parameters:

  • Use loop to control whether to loop playback

  • If you need to insert videos with alpha channel (such as .mov videos), you need to set frame_components=4

Warning

By default, playback has not started, you need to use start to begin playback

Tip

You can use .info to get additional information about the video, such as duration

Example:

video = Video(...).show()

video.start()

self.forward()

video.start(speed=0.5)

self.forward()

video.stop()

Means: play for 1s first, then play at 0.5x speed for 1s, then the frame stays still

color
renderer_cls

alias of VideoRenderer

apply_style(color: JAnimColor | ColorArray | None = None, alpha: Alpha | AlphaArray | None = None, **kwargs) Self

Set the item’s own style, does not affect child items

See also: set()

get_orig() ndarray

Top-left corner of the video

get_horizontal_vect() ndarray

Vector from the top-left corner to the top-right corner of the video

get_horizontal_dist() float

Length of get_horizontal_vect()

get_vertical_vect() ndarray

Vector from the top-left corner to the bottom-left corner of the video

get_vertical_dist() float

Length of get_vertical_vect()

pixel_to_point(x: float, y: float) ndarray

Get the corresponding spatial coordinates through pixel coordinates, can pass floating-point values

  • For example, .pixel_to_point(0, 0) returns the origin position (top-left corner of the image)

  • For example, .pixel_to_point(6, 11) returns the top-left corner of pixel (6, 11)

  • For example, .pixel_to_point(6.5, 11.5) returns the center of pixel (6, 11)

classmethod align_for_interpolate(item1: ImageItem, item2: ImageItem) AlignedData[ImageItem]

Perform data alignment for interpolation

class janim.items.image_item.VideoInfo(file_path: str)

Bases: object

class janim.items.image_item.PixelVideo(file_path: str, *, width: float | None = None, height: float | None = None, min_mag_filter: tuple[int, int] = (9987, 9728), **kwargs)

Bases: Video

Video item

Basically the same as Video, except that when enlarged for display, no smooth interpolation is performed, making pixels clear