# Background Image/Frame for the graph

**URL:** https://forum.graphviz.org/t/background-image-frame-for-the-graph/2232
**Category:** Help
**Created:** [June 5, 2024, 12:06pm UTC](https://forum.graphviz.org/t/background-image-frame-for-the-graph/2232 "2024-06-05T12:06:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![wieserfalke](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/wieserfalke/32/1473_2.png) [@wieserfalke](https://forum.graphviz.org/u/wieserfalke)
#### Post date: [June 5, 2024, 12:06pm UTC](https://forum.graphviz.org/t/background-image-frame-for-the-graph/2232/1 "2024-06-05T12:06:00Z")

</div>

Is there a way to give GraphViz an SVG file that is used as a background image?  
What I want to do is to draw the graph in the center of an SVG file that contains a frame.

I took a look at the image attribute for a node and though maybe a node that contains the background and where everything of the graph is written over it, but I was not able to do it.

I know that one can take the SVG output and then fuse it with other tools, but it would be nice if there is a way directly with GraphViz.

This is for:

> <https://github.com/wireviz/WireViz/issues/354>
>
> We may already have SVG as a vector graphics output, but it still would be nice …if PDF would also be available.

---

<div class="post-metadata">

### Author: ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)
#### Post date: [June 5, 2024, 1:50pm UTC](https://forum.graphviz.org/t/background-image-frame-for-the-graph/2232/2 "2024-06-05T13:50:35Z")

</div>

- there is the **\_background** attribute ([\_background | Graphviz](https://graphviz.org/docs/attrs/background/)), but the image has to be in the **xdot** format ([DOT | Graphviz](https://graphviz.org/docs/outputs/canon/#xdot))!
- for just a frame, you can embed your graph in a cluster & use the **peripheries** attribute ([peripheries | Graphviz](https://graphviz.org/docs/attrs/peripheries/))
- for a legend, see [Adding key or legend? - #12 by mattsmith321](https://forum.graphviz.org/t/adding-key-or-legend/351/12) or [Generate a legend with outputted decision tree figure (jupyter notebook)](https://forum.graphviz.org/t/generate-a-legend-with-outputted-decision-tree-figure-jupyter-notebook/390)
- or you can use **neato** to define a node that uses the **image** attribute(s) and place that node underneath (before) the rest of the graph

 ![p1](https://global.discourse-cdn.com/graphviz/original/2X/f/fad33cd3ee87af42ac26ae587f7f9055de1659b8.png)

---

<div class="post-metadata">

### Author: ![wieserfalke](https://sea2.discourse-cdn.com/graphviz/user_avatar/forum.graphviz.org/wieserfalke/32/1473_2.png) [@wieserfalke](https://forum.graphviz.org/u/wieserfalke)
#### Post date: [June 5, 2024, 2:46pm UTC](https://forum.graphviz.org/t/background-image-frame-for-the-graph/2232/3 "2024-06-05T14:46:33Z")

</div>

I think the last one with **neato** sound promising,  
could you give an example?  
I am currently strugeling to even get a SVG image to display on Windows, I get the error(`Warning: No loadimage plugin for "svg:cairo"`) and I am trying to install cairo. (PNG Works)

---

<div class="post-metadata">

### Author: ![steveroush](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@steveroush](https://forum.graphviz.org/u/steveroush)
#### Post date: [June 5, 2024, 3:11pm UTC](https://forum.graphviz.org/t/background-image-frame-for-the-graph/2232/4 "2024-06-05T15:11:29Z")

</div>

First produce the basic graph, but in **dot** output format:

```auto
dot wireviz1.gv | 
gvpr -cf pin2pin1.gvpr |
neato -n2 >p1.dot

```

Then modify the result (I just did a hand edit) and insert a node with **pos** = midpoint of the above graphs’s **bb** (bounding box). This was inserted:  
`under[pos="260,130" image="image_dir/cow.jpg" label=""]`

Like so:

```auto
graph {
	graph [bb="0,0,522.75,261.5",
		bgcolor="#FFFFFF",
		fontname=arial,
		nodesep=0.33,
		rankdir=LR,
		ranksep=2
	];
// result of hand edit, note my pos is based on bb, but not exact
under[pos="260,130" image="image_dir/cow.jpg" label=""]

	node [fillcolor="#FFFFFF",
		fontname=arial,
		height=0,
		label="\N",
		margin=0,
		shape=none,
		style=filled,
		width=0
	];
	edge [color="#000000",
		constraint=false,
		fontname=arial,
		headclip=false,
		label=" ",
		style=dashed,
		tailclip=false
	];
// and the rest of the graph

```
