def image_to_url(image, colormap=None, origin='<STR_LIT>'):
if isinstance(image, str) and not _is_url(image):<EOL><INDENT>fileformat = os.path.splitext(image)[-<NUM_LIT:1>][<NUM_LIT:1>:]<EOL>with io.open(image, '<STR_LIT:rb>') as f:<EOL><INDENT>img = f.read()<EOL><DEDENT>b64encoded = base64.b64encode(img).decode('<STR_LIT:utf-8>')<EOL>url = '<STR_LIT>'.format(fileformat, b64encoded)<EOL><DEDENT>elif '<STR_LIT>' in image.__class__.__name__:<EOL><INDENT>img = write_png(image, origin=origin, colormap=colormap)<EOL>b64encoded = base64.b64encode(img).decode('<STR_LIT:utf-8>')<EOL>url = '<STR_LIT>'.format(b64encoded)<EOL><DEDENT>else:<EOL><INDENT>url = json.loads(json.dumps(image))<EOL><DEDENT>return url.replace('<STR_LIT:\n>', '<STR_LIT:U+0020>')<EOL>
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`.