veditor.elements.text module

class veditor.elements.text.TextElement(text: str, ttfontname: str, pos_frames: Tuple[int, Optional[int]] = (0, None), margin: Union[int, List[int]] = 0, width: Optional[int] = None, height: Optional[int] = None, top: Optional[Union[veditor.elements.base.BaseElement, int]] = None, right: Optional[Union[veditor.elements.base.BaseElement, int]] = None, left: Optional[Union[veditor.elements.base.BaseElement, int]] = None, bottom: Optional[Union[veditor.elements.base.BaseElement, int]] = None, xy: Tuple = (0, 0), textRGB: Union[str, Tuple] = 'black', fontsize: int = 16, **kwargs)[source]

Bases: veditor.elements.base.FixedElement

set_text_attributes(text: str, ttfontname: str, xy: Tuple = (0, 0), textRGB: Union[str, Tuple] = 'black', fontsize: int = 16, **kwargs)[source]

Set attributes for a text element.

Parameters
  • text (str) – Text to be drawn to img.

  • ttfontname (str) – A filename or file-like object containing a TrueType font.

  • xy (Tuple, optional) – Where to write the text. This value means the coordinates of (x, y). Defaults to (0, 0).

  • textRGB (Union[str, Tuple], optional) – The color of text. Defaults to "black".

  • fontsize (int, optional) – The font size. Defaults to 16.

Examples

>>> from veditor.utils import SampleData
>>> from veditor.elements import TextElement
>>> element = TextElement(text="PyVideoEditor", ttfontname=SampleData().FONT_POKEFONT_PATH)
>>> attribute_names = ["text", "ttfontname", "xy", "textRGB", "fontsize"]
>>> all([hasattr(element, attr) for attr in attribute_names])
True
calc_element_size(text: str, ttfontname: str, fontsize: int = 16, width: Optional[int] = None, height: Optional[int] = None, **kwargs)Tuple[int, int][source]

Basic method for calculating the element size.

Parameters
  • width (Optional[int], optional) – Element width. Defaults to None.

  • height (Optional[int], optional) – Element height. Defaults to None.

Returns

Tu

Return type

Tuple[int, int]

draw_text(img: PIL.Image.Image, text: Optional[str] = None, **kwargs)PIL.Image.Image[source]

Draw text in pillow image (Image.Image) using draw_text_in_pil.

Parameters
  • img (Image.Image) – An image to which text is written.

  • text (Optional[str], optional) – A text string to write. Defaults to None.

Returns

img with text drawn.

Return type

Image.Image

edit(frame: numpy.ndarray[Any, numpy.dtype[numpy.uint8]], pos: int, **kwargs)numpy.ndarray[Any, numpy.dtype[numpy.uint8]][source]

Return frame as it is.

Parameters
  • frame (npt.NDArray[np.uint8]) – The current frame (BGR image) (in the video)

  • pos (int) – The current position (in the video)

Returns

An editied frame.

Return type

npt.NDArray[np.uint8]