code: def _repr_niimgs(niimgs, shorten=True):
      """Pretty printing of niimg or niimgs.
  
      Parameters
      ----------
      niimgs: image or collection of images
          nibabel SpatialImage to repr.
  
      shorten: boolean, default=True
          If True, filenames with more than 20 characters will be
          truncated, and lists of more than 3 file names will be
          printed with only first and last element.
  
      Returns
      -------
      repr: str
          String representation of the image.
      """
      # Maximum number of elements to be displayed
      # Note: should be >= 3 to make sense...
      list_max_display = 3
      # Simple string case
      if isinstance(niimgs, (str, Path)):
          return _short_repr(niimgs, shorten=shorten)
      # Collection case
      if isinstance(niimgs, collections.abc.Iterable):
          if shorten and len(niimgs) > list_max_display:
              tmp = ",\n         ...\n ".join(
                  _repr_niimgs(niimg, shorten=shorten)
                  for niimg in [niimgs[0], niimgs[-1]]
              )
              return f"[{tmp}]"
          elif len(niimgs) > list_max_display:
              tmp = ",\n ".join(
                  _repr_niimgs(niimg, shorten=shorten)
                  for niimg in niimgs
              )
              return f"[{tmp}]"
          else:
              tmp = [
                  _repr_niimgs(niimg, shorten=shorten)
                  for niimg in niimgs
              ]
              return f"[{', '.join(tmp)}]"
      # Nibabel objects have a 'get_filename'
      try:
          filename = niimgs.get_filename()
          if filename is not None:
              return (
                  f"{niimgs.__class__.__name__}"
                  f"('{_short_repr(filename, shorten=shorten)}')"
              )
          else:
              # No shortening in this case
              return (
                  f"{niimgs.__class__.__name__}"
                  f"(\nshape={repr(niimgs.shape)},"
                  f"\naffine={repr(niimgs.affine)}\n)"
              )
      except Exception:
          pass
      return _short_repr(repr(niimgs), shorten=shorten)
  
file_path: nilearn/nilearn/_utils/niimg.py
imports: import collections.abc
  import copy
  import gc
  from pathlib import Path
  from warnings import warn
  import nibabel
  import numpy
  from .helpers import stringify_path
label_desc: Use image node_id 6 for calling a global function with example usage: _repr_niimgs(niimgs, shorten) and returns: _short_repr, _short_repr, str, tmp, str, niimgs, str, _short_repr, str, niimgs, str, repr, str, repr, str, str, tmp, str, str, str, str