docs: def image_to_url(image, colormap=None, origin='upper'):
      """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.  Hint : you can use colormaps from `matplotlib.cm`.
      """
      if hasattr(image, 'read'):
          # We got an image file.
          if hasattr(image, 'name'):
              # We try to get the image format from the file name.
              fileformat = image.name.lower().split('.')[-1]
          else:
              fileformat = 'png'
          url = 'data:image/{};base64,{}'.format(
              fileformat, base64.b64encode(image.read()).decode('utf-8'))
      elif (not (isinstance(image, text_type) or
                 isinstance(image, binary_type))) and hasattr(image, '__iter__'):
          # We got an array-like object.
          png = write_png(image, origin=origin, colormap=colormap)
          url = 'data:image/png;base64,' + base64.b64encode(png).decode('utf-8')
      else:
          # We got an URL.
          url = json.loads(json.dumps(image))
  
      return url.replace('\n', ' ')