code: def get_gallery_images_in_notebook(
      nb_filepath: Path,
  ) -> Generator[GalleryImage, None, None]:
      """
      Return all gallery images in a notebook
      """
      nb = nbformat.read(nb_filepath.open(), as_version=4)
      nb_cells = nb["cells"]
      notebook_name = nb_filepath.stem
  
      # The preceeding_cells and the output node that contains
      # an image for the gallery
      gallery_output_nodes = (
          (nb_cells[:ii], node)
          for ii, cell in enumerate(nb_cells)
          if GALLERY_TAG in cell.source
          for node in cell.outputs
          if node.output_type == "display_data"
      )
  
      for preceeding_cells, output_node in gallery_output_nodes:
          title = get_gallery_image_title(preceeding_cells)
          anchor = sanitize_filename(title)
          relpath = THUMBNAILS_DIR / f"{notebook_name}-{anchor}.png"
          create_thumbnail(output_node, THIS_DIR / relpath)
          target = f"/reference/{notebook_name}.qmd#{anchor}"
          yield GalleryImage(relpath, title, target)
  
imports: import base64
  import io
  import itertools
  import re
  from dataclasses import dataclass
  from pathlib import Path
  from typing import Generator, Sequence
  import nbformat
  import PIL.Image
  from nbformat.notebooknode import NotebookNode
  from quartodoc.pandoc.blocks import Div
  from quartodoc.pandoc.components import Attr
  from quartodoc.pandoc.inlines import Image, Link
label_desc: Use image node_id 4 for calling a global function with example usage: get_gallery_images_in_notebook(nb_filepath) without return types