Can I put an image in a node by referencing a url.

I want to put an image in a node, but the image is stored on a web site...  Is this possible to do? 

I create the dot language as below, but when I run it through dot.exe it tells me that there is a syntax error.  If I take the IMG tag out, it seems to work, but of course no image is displayed.

strict digraph "test" {
 edge["fontsize"="8px","color"="#97A2A6"]
 node["fontsize"="8px","shape"="rectangle","margin"=0,"pad"=0,"fillcolor"="#E8F7E2","style"="filled,rounded"]

 "250" ["label"=<My Node<BR/><IMG SRC="http://mywebsite/images/node1.png" />>]
 "177" ["label"=<My Other Node<BR/><IMG SRC="http://mywebsite/images/node1.png" />>]

 "250"  -> "177" ["label"="Test","dir"="forward","style"="dashed","fontcolor"="gray","color"="gray"];
}

 

Something like this used to

Something like this used to be possible, but was removed in 2003 because of security concerns. At present, files for images must reside on the local file system. (If run in server mode, files can be further restricted to certain directories.)

I don't understand the

I don't understand the security concern part.  I mean, a web page can have images where the source is local or remote...

To be honest, I can't

To be honest, I can't remember the exact reasons (it was 11 years ago) and the comments in the code are a bit vague now. I think the problem had to do with how it was implemented, where we used popen to call curl on the url, and the url could be written to have popen do more than fetch the file. At the time, it was probably easier to remove the feature than to bullet proof the code. It could probably be written using libcurl now without any security concerns.

Hi, your .dot file cannot be

Hi,

your .dot file cannot be processed even with local image files.

I used this very simple sample instead:
digraph G { imgnode[image="h.png" label=""]; }

Then I processed it:
dot -Tsvg h.dot > h.dot.svg

Finally I replaced the local file refrence in the generated .svg by a link:
sed "s#\(href=\"\)#\1http://127.0.0.1/#"

And the modified .svg works fine.

Hermann.

Assuming h.png is the same

Assuming h.png is the same size as the remote file.

> Assuming h.png is the same

> Assuming h.png is the same size as the remote file.
>
Yes, better "wget" the remote file first and use it in layout then.

This bash script (for Linux or Cygwin under Windows) does it all:

$ cat doit 
#!/bin/bash
d=`dirname $2W`
f=`basename $2`
rm -f $f 
wget -q $2
dot -Tsvg $1 | sed "s#\(href=\"\)"$f"\"#\1"$d"/"$f"\"#" > $1.svg

I did store "h.png" on a remote server and took previous h.dot sample, here is how the script gets called:

$ ./doit h.dot https://www.ibm.com/developerworks/community/blogs/HermannSW/resource/BL...

$ grep xlink h.dot.svg 
 viewBox="0.00 0.00 62.00 66.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<image xlink:href="https://www.ibm.com/developerworks/community/blogs/HermannSW/resource/BLOGS_UPLOADED_IMAGES/h.png" width="33px" height="51px" preserveAspectRatio="xMinYMin meet" x="10.5" y="-54.5"/>

Then I stored the generated .svg on my private website, you can click and see that remote imgnode fetch works:
http://stamm-wilbrandt.de/en/forum/h.dot.svg

Hermann <GraphvizFiddle/> <Viz.js_form10/>

Recent comments