def imsave(filename, data, maxval=None, pam=False):
try:<EOL><INDENT>netpbm = NetpbmFile(data, maxval=maxval)<EOL>netpbm.write(filename, pam=pam)<EOL><DEDENT>finally:<EOL><INDENT>netpbm.close()<EOL><DEDENT>
Write image data to Netpbm file.

    Examples
    --------
    >>> image = numpy.array([[0, 1],[65534, 65535]], dtype=numpy.uint16)
    >>> imsave('_tmp.pgm', image)