code: def generate_images(
      image_path_iterator: Iterator[str], dynamic: bool = False
  ) -> List[str]:
      """Generate images from the current plotters.
  
      The file names are taken from the ``image_path_iterator`` iterator.
  
      A gif will be created if a plotter has a ``_gif_filename`` attribute.
      Otherwise, depending on the value of ``dynamic``, either a ``.png`` static image
      or a ``.vtksz`` file will be created.
  
      Parameters
      ----------
      image_path_iterator : Iterator[str]
          An iterator that yields the path to the next image to be saved.
  
      dynamic : bool, default: False
          Whether to save a static ``.png`` image or a ``.vtksz`` (interactive)
          file.
  
      Returns
      -------
      list[str]
          A list of the names of the images that were created.
      """
      image_names = []
      figures = pyvista.plotting.plotter._ALL_PLOTTERS
      for plotter in figures.values():
          _process_events_before_scraping(plotter)
          fname = next(image_path_iterator)
          # Make sure the extension is "png"
          fname_withoutextension, _ = os.path.splitext(fname)
          fname = fname_withoutextension + ".png"
  
          if hasattr(plotter, "_gif_filename"):
              # move gif to fname
              fname = fname[:-3] + "gif"
              shutil.move(plotter._gif_filename, fname)
              image_names.append(fname)
          else:
              plotter.screenshot(fname)
              if not dynamic or plotter.last_vtksz is None:
                  image_names.append(fname)
              else:  # pragma: no cover
                  fname = fname[:-3] + "vtksz"
                  with open(fname, "wb") as f:
                      f.write(plotter.last_vtksz)
                      image_names.append(fname)
  
      pyvista.close_all()  # close and clear all plotters
      return image_names
  
file_path: pyvista/pyvista/plotting/utilities/sphinx_gallery.py
imports: import os
  import shutil
  from typing import Iterator, List
  import pyvista
label_desc: Use image node_id 4 for calling a global function with example usage: generate_images(image_path_iterator, dynamic) and returns: image_names