-1

I am having problem including image in node in graphviz. I tried both including image in node via image="name.svg" and via <IMG SRC="name.svg" /> in HTML-like label. I also tried using different image formats (svg, jpg, png), but when exporting I always get message:

Warning: No such file or directory while opening name.svg
Warning: No or improper image="name.svg" for node "somenode"

.dot file looks like:

digraph {

    node1[image="image.svg", label=""]
    
    node2[  label=
        <A
        <IMG SRC="image.svg" />> ]

    node1 -> node2 }

image.svg is located in same directory as .dot file (output of ls -la):

total 96
drwxrwxr-x  2 filip filip  4096 maj  8 07:55 .
drwxr-xr-x 34 filip filip  4096 maj  8 07:56 ..
-rw-rw-r--  1 filip filip 85030 maj  7 17:05 image.svg
-rw-rw-r--  1 filip filip   117 maj  8 07:54 mygraph.dot

My OS is Ubuntu 20.04.3 LTS.

I have already looked at many other questions regarding this problem, but none of the solutions given seem to help.

Any suggestions?

Filip Ž
  • 11
  • 3
  • Please [edit] your question to include the full complete `.dot` file as a [mcve]. Also show the output of `ls -la` in the directory you are trying to call the `dot` program. And add the command line arguments of the `dot` execution and the complete output you get from it. – Progman May 07 '22 at 18:17
  • You might want to check other questions like https://stackoverflow.com/questions/49819164/graphviz-nodes-of-svg-images-do-not-get-inserted-if-output-is-svg – Progman May 08 '22 at 06:50
  • Thank you for advices! However solution from https://stackoverflow.com/questions/49819164/graphviz-nodes-of-svg-images-do-not-get-inserted-if-output-is-svg didn't help in my case. I managed to find the solution for me, I will post it as an answer. – Filip Ž May 08 '22 at 09:53
  • 1
    Does this answer your question? [What exactly is current working directory?](https://stackoverflow.com/questions/45591428/what-exactly-is-current-working-directory) – tripleee May 08 '22 at 10:25

1 Answers1

1

When retrying whole process in different ways I found how it should be done, although I don't have enough knowledge to understand why this happens.

The thing is, command dot -Tsvg mygraph.dot > mygraph.svg must be run from the directory where mygraph.dot is stored. Also, image.svg must be located in this same directory or in one of the subdirectories. If, for example, mygraph.dot is stored inside dir1, running

dot -Tsvg dir1/mygraph.dot > dir1/mygraph.svg

from the parent directory of dir1 won't work.

Also, image inside HTML-like label should be inside a table:

node[   label=
        <<TABLE><TR><TD>
                <IMG 
                    SRC="/home/filip/dir2/images/image.svg"
                />
        </TD></TR></TABLE>>
]

It is possible all this is stated somewhere in the documentation and I just didn't notice.

Also, maybe worth mentioning is that on Ubuntu, if I wanted image.svg embedded in output file, I had to additionaly install librsvg2-dev and librgraphviz-dev packages, then run:

dot -Tsvg:cairo mygraph.dot > mygraph.svg
Filip Ž
  • 11
  • 3