code: def image_to_url(image, colormap=None, origin='upper'):
      
      if isinstance(image, str) and not _is_url(image):
          fileformat = os.path.splitext(image)[-1][1:]
          with io.open(image, 'rb') as f:
              img = f.read()
          b64encoded = base64.b64encode(img).decode('utf-8')
          url = 'data:image/{};base64,{}'.format(fileformat, b64encoded)
      elif 'ndarray' in image.__class__.__name__:
          img = write_png(image, origin=origin, colormap=colormap)
          b64encoded = base64.b64encode(img).decode('utf-8')
          url = 'data:image/png;base64,{}'.format(b64encoded)
      else:
          # Round-trip to ensure a nice formatted json.
          url = json.loads(json.dumps(image))
      return url.replace('\n', ' ')
docs: 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`.