Skip to main content

AssemblyLine.sign

find_font_file_by_name

def find_font_file_by_name(font_name: str,
search_dirs: List[str]) -> Optional[str]

Recursively search for a font file by name in the specified directories.

This function appends '.ttf' to the font name if it is not already present and searches through each directory in search_dirs recursively for a file that matches the font name (case-insensitive).

Arguments

  • font_name str - The name of the font to search for (without path).
  • search_dirs List[str] - A list of directories to search.

Returns

  • Optional[str] - The full path to the font file if found; otherwise, None.

get_font

def get_font(
font_name: Optional[str] = None,
font_size: int = 48
) -> Union[ImageFont.ImageFont, ImageFont.FreeTypeFont]

Loads a font by name from candidate directories and returns an ImageFont instance.

If font_name is provided, it may be either a full path to a font file or a font name (without a path). In the latter case, the function will search for the font in /var/www/.fonts and /usr/share/fonts/truetype/, automatically appending '.ttf' if necessary. If no font is found, the function falls back to the default Pillow font.

Arguments

  • font_name Optional[str] - The desired font's full path or name. Defaults to None.
  • font_size int - The size of the font to be used. Defaults to 48.

Returns

  • ImageFont.ImageFont - The loaded font instance.

create_signature

def create_signature(name: str,
output_file: str,
signature_prefix: str = "/s/",
font_name: Optional[str] = None,
font_size: int = 48) -> None

Creates an image file that simulates a signature.

The signature image is generated by combining the provided signature_prefix (for example, "/s/" or "s/") with the person's name. The text size is measured to create an image with appropriate dimensions, and then the text is drawn onto a white background. The final image is saved to the specified output file path.

Arguments

  • name str - The person's name to be signed.
  • output_file str - The full file path where the image will be written.
  • signature_prefix str - The signature prefix to use (e.g., "/s/" or "s/"). Defaults to "/s/".
  • font_name Optional[str] - The font's full path or name (without path). Defaults to None.
  • font_size int - The size of the font to be used. Defaults to 48.