How to save <IPython.core.display.Image object> as png file

769 Views Asked by At

When I run this code it's showing <IPython.core.display.Image object> but I need to save the file as png on my computer, how to do this

This is the code to create Unix Directory Structure Using Graphviz

    import pydot
    import os
    from IPython.display import Image, display

    rootdir = "/home/niranjan/Pictures/proj1"
    G = pydot.Dot(graph_type="digraph")
    for root, dirs, files in os.walk(rootdir):
        for subdir in dirs:
            node = pydot.Node(subdir,style="filled",fillcolor="green")
            G.add_node(node)
            edge = pydot.Edge(root.split("/")[-1],subdir)
            G.add_edge(edge)

    for file in files:
        node = pydot.Node(file,style="filled",fillcolor="yellow")
        G.add_node(node)
        edge = pydot.Edge(root.split("/")[-1],file)
        G.add_edge(edge)



    im = Image(G.create_png())
    display(im)
1

There are 1 best solutions below

0
hbstha123 On

You can use: G.write_png("file.png") You can also save the file as jpeg or other formats available.