code: def _image_type_from_file(filename: PathLike[str] | str) -> str:
      with open(filename, "rb") as f:
          header = f.read(32)  # 32 bytes
  
      # Bitmap
      # https://en.wikipedia.org/wiki/BMP_file_format#Bitmap_file_header
      if header.startswith(b"BM"):
          return "bmp"
  
      # GIF
      # https://en.wikipedia.org/wiki/GIF#File_format
      if header.startswith((b"GIF87a", b"GIF89a")):
          return "gif"
  
      # JPEG data
      # https://en.wikipedia.org/wiki/JPEG_File_Interchange_Format#File_format_structure
      if header.startswith(b"\xFF\xD8"):
          return "jpeg"
  
      # Portable Network Graphics
      # https://en.wikipedia.org/wiki/PNG#File_header
      if header.startswith(b"\x89PNG\r\n\x1A\n"):
          return "png"
  
      # Scalable Vector Graphics
      # https://svgwg.org/svg2-draft/struct.html
      if b"<svg" in header.lower():
          return "svg+xml"
  
      # TIFF
      # https://en.wikipedia.org/wiki/TIFF#Byte_order
      if header.startswith((b"MM", b"II")):
          return "tiff"
  
      # WebP
      # https://en.wikipedia.org/wiki/WebP#Technology
      if header.startswith(b"RIFF") and header[8:12] == b"WEBP":
          return "webp"
  
      msg = "Could not detect image type!"
      raise ValueError(msg)
  
file_path: sphinx/sphinx/util/images.py
imports: from __future__ import annotations
  import base64
  from os import path
  from typing import TYPE_CHECKING, NamedTuple, overload
  import imagesize
label_desc: Use image node_id 7 for calling a global function with example usage: _image_type_from_file(filename) and returns: str, str, str, str, str, str, str