docs: def all_thumbnails(path, recursive=True, prefix=None, subdir=None):
      """
      Return a dictionary referencing all files which match the thumbnail format.
  
      Each key is a source image filename, relative to path.
      Each value is a list of dictionaries as explained in `thumbnails_for_file`.
      """
      if prefix is None:
          prefix = settings.THUMBNAIL_PREFIX
      if subdir is None:
          subdir = settings.THUMBNAIL_SUBDIR
      thumbnail_files = {}
      if not path.endswith('/'):
          path = '%s/' % path
      len_path = len(path)
      if recursive:
          all = os.walk(path)
      else:
          files = []
          for file in os.listdir(path):
              if os.path.isfile(os.path.join(path, file)):
                  files.append(file)
          all = [(path, [], files)]
      for dir_, subdirs, files in all:
          rel_dir = dir_[len_path:]
          for file in files:
              thumb = re_thumbnail_file.match(file)
              if not thumb:
                  continue
              d = thumb.groupdict()
              source_filename = d.pop('source_filename')
              if prefix:
                  source_path, source_filename = os.path.split(source_filename)
                  if not source_filename.startswith(prefix):
                      continue
                  source_filename = os.path.join(
                      source_path, source_filename[len(prefix):])
              d['options'] = d['options'] and d['options'].split('_') or []
              if subdir and rel_dir.endswith(subdir):
                  rel_dir = rel_dir[:-len(subdir)]
              # Corner-case bug: if the filename didn't have an extension but did
              # have an underscore, the last underscore will get converted to a
              # '.'.
              m = re.match(r'(.*)_(.*)', source_filename)
              if m:
                  source_filename = '%s.%s' % m.groups()
              filename = os.path.join(rel_dir, source_filename)
              thumbnail_file = thumbnail_files.setdefault(filename, [])
              d['filename'] = os.path.join(dir_, file)
              thumbnail_file.append(d)
      return thumbnail_files