code: def synthesize_text_img(
      text: str,
      font_size: int = 32,
      font_family: Optional[str] = None,
      background_color: Optional[Tuple[int, int, int]] = None,
      text_color: Optional[Tuple[int, int, int]] = None,
  ) -> Image:
      """Generate a synthetic text image
  
      Args:
      ----
          text: the text to render as an image
          font_size: the size of the font
          font_family: the font family (has to be installed on your system)
          background_color: background color of the final image
          text_color: text color on the final image
  
      Returns:
      -------
          PIL image of the text
      """
      background_color = (
          (0, 0, 0) if background_color is None else background_color
      )
      text_color = (255, 255, 255) if text_color is None else text_color
  
      font = get_font(font_family, font_size)
      left, top, right, bottom = font.getbbox(text)
      text_w, text_h = right - left, bottom - top
      h, w = int(round(1.3 * text_h)), int(round(1.1 * text_w))
      # If single letter, make the image square, otherwise expand to meet the text size
      img_size = (h, w) if len(text) > 1 else (max(h, w), max(h, w))
  
      img = Image.new("RGB", img_size[::-1], color=background_color)
      d = ImageDraw.Draw(img)
  
      # Offset so that the text is centered
      text_pos = (
          int(round((img_size[1] - text_w) / 2)),
          int(round((img_size[0] - text_h) / 2)),
      )
      # Draw the text
      d.text(text_pos, text, font=font, fill=text_color)
      return img
  
file_path: doctr/doctr/datasets/generator/base.py
imports: import random
  from typing import Any, Callable, List, Optional, Tuple, Union
  from PIL import Image, ImageDraw
  from doctr.io.image import tensor_from_pil
  from doctr.utils.fonts import get_font
  from ..datasets import AbstractDataset
label_desc: Use image node_id 1 for calling a global function with example usage: synthesize_text_img(text, font_size, font_family, background_color, text_color) and returns: img