Skip to content

Commit 89af43d

Browse files
committed
update readme regarding images
1 parent 64c9aa3 commit 89af43d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Use graphviz with pure java. Create graphviz models using java code and convert
99
#### [Prerequisites ](#user-content-prerequisites)
1010
#### [API ](#user-content-api)
1111
#### [Examples ](#user-content-examples)
12+
#### [Images ](#user-content-images)
1213
#### [Configuration ](#user-content-configuration)
1314

1415

@@ -266,6 +267,40 @@ results in this graphics:
266267

267268
<img src="https://rawgit.com/nidi3/graphviz-java/master/graphviz-java/example/ex4-2.png" width="400">
268269

270+
## Images
271+
Images can be included in graphviz in two ways.
272+
273+
One possibility is using the <img> tag inside a HTML label:
274+
275+
[//]: # (img)
276+
```java
277+
Graphviz.useEngine(new GraphvizCmdLineEngine());
278+
Graphviz g = Graphviz.fromGraph(graph()
279+
.with(node(Label.html("<table border='0'><tr><td><img src='graphviz.png' /></td></tr></table>"))));
280+
g.basedir(new File("example")).render(Format.PNG).toFile(new File("example/ex7.png"));
281+
```
282+
[//]: # (end)
283+
<img src="https://rawgit.com/nidi3/graphviz-java/master/graphviz-java/example/ex7.png" width="200">
284+
285+
Because viz.js [does not support \<img> tags](https://github.com/mdaines/viz.js/issues/125),
286+
**this works only when using the command line engine**.
287+
288+
The other way is the image attribute of a node:
289+
290+
[//]: # (image)
291+
```java
292+
Graphviz.useEngine(new GraphvizV8Engine());
293+
Graphviz g = Graphviz.fromGraph(graph()
294+
.with(node(" ").with(Size.std().margin(.8, .7), Image.of("graphviz.png"))));
295+
g.basedir(new File("example")).render(Format.PNG).toFile(new File("example/ex8.png"));
296+
```
297+
[//]: # (end)
298+
<img src="https://rawgit.com/nidi3/graphviz-java/master/graphviz-java/example/ex8.png" width="200">
299+
300+
This works with all engines.
301+
302+
In both cases, the `basedir()` method can be used to define where relative paths are looked up.
303+
269304
## Configuration
270305
The size of the resulting image, the rendering engine and the output format can be configured:
271306

0 commit comments

Comments
 (0)