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:
PointsImage 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:
ImageItemImage 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:
ImageItemVideo frame, used to extract a single frame image from the video at a specified time
file_path: File pathframe_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,PointsVideo 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 defaultCall
startto begin playback from the current position, can pass aspeedparameter to specify playback speedCall
stopto pause at the current positionCall
seekto jump the video progress to a specified number of seconds
Parameters:
Use
loopto control whether to loop playbackIf you need to insert videos with alpha channel (such as
.movvideos), you need to setframe_components=4
Warning
By default, playback has not started, you need to use
startto begin playbackTip
You can use
.infoto get additional information about the video, such as durationExample:
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:
VideoVideo item
Basically the same as
Video, except that when enlarged for display, no smooth interpolation is performed, making pixels clear