code: def image_to_url(
      image: Any,
      colormap: Optional[Callable] = None,
      origin: str = "upper",
  ) -> str:
      """
      Infers the type of an image argument and transforms it into a URL.
  
      Parameters
      ----------
      image: string, file or array-like object
          * If string, it will be written directly in the output file.
          * If file, it's content will be converted as embedded in the
            output file.
          * If array-like, it will be converted to PNG base64 string and
            embedded in the output.
      origin: ['upper' | 'lower'], optional, default 'upper'
          Place the [0, 0] index of the array in the upper left or
          lower left corner of the axes.
      colormap: callable, used only for `mono` image.
          Function of the form [x -> (r,g,b)] or [x -> (r,g,b,a)]
          for transforming a mono image into RGB.
          It must output iterables of length 3 or 4, with values between
          0. and 1.  You can use colormaps from `matplotlib.cm`.
  
      """
      if isinstance(image, str) and not _is_url(image):
          fileformat = os.path.splitext(image)[-1][1:]
          with open(image, "rb") as f:
              img = f.read()
          b64encoded = base64.b64encode(img).decode("utf-8")
          url = f"data:image/{fileformat};base64,{b64encoded}"
      elif "ndarray" in image.__class__.__name__:
          img = write_png(image, origin=origin, colormap=colormap)
          b64encoded = base64.b64encode(img).decode("utf-8")
          url = f"data:image/png;base64,{b64encoded}"
      else:
          # Round-trip to ensure a nice formatted json.
          url = json.loads(json.dumps(image))
      return url.replace("\n", " ")
  
imports: import base64
  import collections
  import copy
  import json
  import math
  import os
  import re
  import tempfile
  import uuid
  from contextlib import contextmanager
  from typing import Any, Callable, Dict, Iterable, Iterator, List, Optional, Sequence, Tuple, Type, Union
  from urllib.parse import urlparse, uses_netloc, uses_params, uses_relative
  import numpy
  from branca.element import Element, Figure
  from branca.utilities import _locations_mirror, _parse_size, none_max, none_min, write_png
label_desc: Use image node_id 6 for calling a global function with example usage: image_to_url(image, colormap, origin) and returns: url