human
Give me a the Python program you requested given the following:
Complete the below
def imread(fname, format=None):

    ''''Read an image from a file into an array.
    *fname* may be a string path, a valid URL, or a Python
    file-like object.  If using a file object, it must be opened in binary
    mode.
    If *format* is provided, will try to read file of that type,
    otherwise the format is deduced from the filename.  If nothing can
    be deduced, PNG is tried.
    Return value is a :class:`numpy.array`.  For grayscale images, the
    return array is MxN.  For RGB images, the return value is MxNx3.
    For RGBA images the return value is MxNx4.
    matplotlib can only read PNGs natively, but if `PIL
    <http://www.pythonware.com/products/pil/>`_ is installed, it will
    use it to load the image and return an array (if possible) which
    can be used with :func:`~matplotlib.pyplot.imshow`. Note, URL strings
    may not be compatible with PIL. Check the PIL documentation for more
    information.'
    '''
assistant
#Here is the Python program you requested.
    def pilread(fname):
        u'try    to    load    the    image    with    PIL    or    return    None'
        try:
            from PIL import Image
        except ImportError:
            return None
        with Image.open(fname) as image:
            return pil_to_array(image)
    handlers = {u'png': _png.read_png}
    if (format is None):
        if isinstance(fname, six.string_types):
            parsed = urlparse(fname)
            if (len(parsed.scheme) > 1):
                ext = u'png'
            else:
                (basename, ext) = os.path.splitext(fname)
                ext = ext.lower()[1:]
        elif hasattr(fname, u'name'):
            (basename, ext) = os.path.splitext(fname.name)
            ext = ext.lower()[1:]
        else:
            ext = u'png'
    else:
        ext = format
    if (ext not in handlers):
        im = pilread(fname)
        if (im is None):
            raise ValueError((u'Only    know    how    to    handle    extensions:    %s;    with    Pillow    installed    matplotlib    can    handle    more    images' % list(handlers)))
        return im
    handler = handlers[ext]
    if isinstance(fname, six.string_types):
        parsed = urlparse(fname)
        if (len(parsed.scheme) > 1):
            fd = BytesIO(urlopen(fname).read())
            return handler(fd)
        else:
            with open(fname, u'rb') as fd:
                return handler(fd)
    else:
        return handler(fname)