ndio/convert/png.py
def save(filename, numpy_data):
    """
    Export a numpy array to a png file.

    Arguments:
        filename (str): A filename to which to save the png data
        numpy_data (numpy.ndarray OR str): The numpy array to save to png.
            OR a string: If a string is provded, it should be a binary png str

    Returns:
        str. The expanded filename that now holds the png data

    Raises:
        ValueError: If the save fails; for instance if the binary string data
            cannot be coerced into a png, or perhaps your numpy.ndarray is
            ill-formed?
    """
    # Expand filename to be absolute
    png_filename = os.path.expanduser(filename)

    if type(numpy_data) is str:
        fp = open(png_filename, "wb")
        fp.write(numpy_data)
        fp.close()
        return png_filename

    try:
        if numpy_data.dtype.name != 'uint8':
            m = 'I'
            img = Image.fromarray(numpy_data, mode=m)
        else:
            img = Image.fromarray(numpy_data)
        img.save(png_filename)
    except Exception as e:
        raise ValueError("Could not save png file {0}.".format(png_filename))
    return png_filename
def save(filename, numpy_data):
    # Expand filename to be absolute
    png_filename = os.path.expanduser(filename)

    if type(numpy_data) is str:
        fp = open(png_filename, "wb")
        fp.write(numpy_data)
        fp.close()
        return png_filename

    try:
        if numpy_data.dtype.name != 'uint8':
            m = 'I'
            img = Image.fromarray(numpy_data, mode=m)
        else:
            img = Image.fromarray(numpy_data)
        img.save(png_filename)
    except Exception as e:
        raise ValueError("Could not save png file {0}.".format(png_filename))
    return png_filename
def save ( filename , numpy_data ) : # Expand filename to be absolute png_filename = os . path . expanduser ( filename ) if type ( numpy_data ) is str : fp = open ( png_filename , "wb" ) fp . write ( numpy_data ) fp . close ( ) return png_filename try : if numpy_data . dtype . name != 'uint8' : m = 'I' img = Image . fromarray ( numpy_data , mode = m ) else : img = Image . fromarray ( numpy_data ) img . save ( png_filename ) except Exception as e : raise ValueError ( "Could not save png file {0}." . format ( png_filename ) ) return png_filename
Export a numpy array to a png file.

    Arguments:
        filename (str): A filename to which to save the png data
        numpy_data (numpy.ndarray OR str): The numpy array to save to png.
            OR a string: If a string is provded, it should be a binary png str

    Returns:
        str. The expanded filename that now holds the png data

    Raises:
        ValueError: If the save fails; for instance if the binary string data
            cannot be coerced into a png, or perhaps your numpy.ndarray is
            ill-formed?
Export a numpy array to a png file .