WireViz icon indicating copy to clipboard operation
WireViz copied to clipboard

Image Types

Open kvid opened this issue 9 months ago • 5 comments

I noticed that the SVG image for a connector is not shown in the PNG output. I wonder if this is also observed by others. JPG, PNG, and GIF images in connectors seems to work fine, but a TIF image was rejected by Graphviz. It would be nice to create a test use case with all image types expected to work, and perhaps a separate (sub-)issue for unexpected outputs for such a test use case.

Originally posted by @kvid in https://github.com/wireviz/WireViz/issues/443#issuecomment-2645515636

Preliminary test use case YAML input:

connectors:
  png: &png
    pincount: 4
    image:
      src: resources/MolexKK254_4-pin.png
  jpg:
    <<: *png
    image:
      src: resources/MolexKK254_4-pin.jpg
  svg:
    <<: *png
    image:
      src: resources/MolexKK254_4-pin.svg
  gif:
    <<: *png
    image:
      src: resources/MolexKK254_4-pin.gif
#  tif:
#    <<: *png
#    image:
#      src: resources/MolexKK254_4-pin.tif
#  webp:
#    <<: *png
#    image:
#      src: resources/MolexKK254_4-pin.webp
cables:
  w:
    category: bundle
    colors: [YE]
    length: 1
connections:
  - - png: [1]
    - w.: [1]
    - jpg: [1]
    - w.: [1]
    - svg: [1]
    - w.: [1]
    - gif: [1]
#    - w.: [1]
#    - tif: [1]
#    - w.: [1]
#    - webp: [1]

Image files expected to be in a resources subfolder: Image MolexKK254_4-pin.png Image MolexKK254_4-pin.jpg Image MolexKK254_4-pin.svg Image MolexKK254_4-pin.gif

Please suggest including other image types you are able to use or any kind of improvements.

kvid avatar Feb 22 '25 01:02 kvid

My host OS:

> wsl -l -v && ver
  NAME            STATE           VERSION
* Ubuntu-20.04    Running         1
  Ubuntu          Running         1

Microsoft Windows [Version 10.0.19045.5371]

My local environment (used pip3 install -e . to install WireViz):

$ git status && wireviz -V && python -V && lsb_release -d && dot -v </dev/null
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

WireViz 0.4.1
Python 3.8.10
Description:    Ubuntu 20.04.4 LTS
dot - graphviz version 2.43.0 (0)
libdir = "/usr/lib/x86_64-linux-gnu/graphviz"
Activated plugin library: libgvplugin_dot_layout.so.6
Using layout: dot:dot_layout
Activated plugin library: libgvplugin_core.so.6
Using render: dot:core
Using device: dot:dot:core
The plugin configuration file:
        /usr/lib/x86_64-linux-gnu/graphviz/config6a
                was successfully loaded.
    render      :  cairo dot dot_json fig gd json json0 map mp pic pov ps svg tk visio vml vrml xdot xdot_json
    layout      :  circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
    textlayout  :  textlayout
    device      :  canon cmap cmapx cmapx_np dot dot_json eps fig gd gd2 gif gv imap imap_np ismap jpe jpeg jpg json json0 mp pdf pic plain plain-ext png pov ps ps2 svg svgz tk vdx vml vmlz vrml wbmp webp x11 xdot xdot1.2 xdot1.4 xdot_json xlib
    loadimage   :  (lib) eps gd gd2 gif jpe jpeg jpg png ps svg webp xbm

Running test use case:

$ wireviz issue445.yml

WireViz 0.4.1
Input file:   issue445.yml
Output file:  issue445.[html|png|svg|tsv]
Warning: No loadimage plugin for "svg:cairo"

Output: Image issue445.png

Image issue445.svg

Image issue445.svg if PR #443 is accepted

kvid avatar Feb 22 '25 02:02 kvid

Interestingly enough wireviz immediately crashes macOS when running your example file with:

WireViz 0.4.1
Input file:   wire.yml
Output file:  wire.[html|png|svg]
Traceback (most recent call last):
  File "/Users/michaelwagner/.local/pipx/venvs/wireviz/lib/python3.12/site-packages/graphviz/backend/execute.py", line 88, in run_check
    proc.check_returncode()
  File "/usr/local/Cellar/[email protected]/3.12.9/Frameworks/Python.framework/Versions/3.12/lib/python3.12/subprocess.py", line 504, in check_returncode
    raise CalledProcessError(self.returncode, self.args, self.stdout,
subprocess.CalledProcessError: Command '[PosixPath('dot'), '-Kdot', '-Tpng', '-O', 'wire']' died with <Signals.SIGABRT: 6>.

I'm going to look further into this issue later but it seems Graphviz on macOS doesn't like jpg and gif. However, just using the png and svg you can see the scaling issue that does not appear to be present in yours.

Image issue445.png

Image issue445.svg

TheMDev avatar Feb 22 '25 02:02 TheMDev

Thank's for responding super-quickly! Please edit your comment above to add the versions of your OS, Python, and Graphviz. The warning I got from Graphviz also indicates there might be some optional plugins that could make a difference, so I edited my comment above to use dot -v for also outputting plugin information, but I don't know how to add any missing plugin.

kvid avatar Feb 22 '25 03:02 kvid

After running dot-v and comparing our outputs, I was confused by the gap in the versions. Graphviz 2 is some 10 years old at this point. It appears Debian and Ubuntu repos have decided not to update, and I was unable to find 3rd party repos that provide a recent version as well. The only choice for Debian and Ubuntu is to download or build from the source. Interestingly enough, Fedora has the same version of Graphviz as I have on macOS.

macOS Sequoia 15 Python 3.12.7

dot - graphviz version 12.2.1 (20241206.2353)
libdir = "/usr/local/Cellar/graphviz/12.2.1/lib/graphviz"
Activated plugin library: libgvplugin_dot_layout.6.dylib
Using layout: dot:dot_layout
Activated plugin library: libgvplugin_core.6.dylib
Using render: dot:core
Using device: dot:dot:core
The plugin configuration file:
	/usr/local/Cellar/graphviz/12.2.1/lib/graphviz/config6
		was successfully loaded.
    render	:  cairo dot dot_json fig gd json json0 map pic pov ps quartz svg svg_inline tk vrml xdot xdot_json
    layout	:  circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
    textlayout	:  textlayout
    device	:  bmp canon cgimage cmap cmapx cmapx_np dot dot_json eps exr fig gd gd2 gif gv icns ico imap imap_np ismap jp2 jpe jpeg jpg json json0 kitty kittyz pct pdf pic pict plain plain-ext png pov ps ps2 psd sgi svg svg_inline svgz tga tif tiff tk vrml vt vt-24bit vt-4up vt-6up vt-8up wbmp webp xdot xdot1.2 xdot1.4 xdot_json
    loadimage	:  (lib) bmp eps gd gd2 gif jpe jpeg jpg pdf png ps svg webp xbm

TheMDev avatar Feb 24 '25 16:02 TheMDev

Graphviz's layout engines (the commands like dot, neato, etc. that produce different types of graphs from the input graph definition) provide a whole range of output file formats, not all of which are implemented in the base library. Even for those that are, many plugins provide their own implementation of the same format, leading to multiple different ways of generating a particular type of output file.

(Some methods will also have different capabilities, for example SVG can be generated by Graphviz core or by the Cairo rendering plugin. If cairo is used, all of the text elements in the graph will be rendered to paths. The core SVG renderer uses <text> elements to embed text, so that it's rendered by the SVG interpreter that displays the graphic.)

For any given output file format foo (what you get from dot -Tfoo graph.gv), the available default and non-default output options can be examined by running dot -Tfoo: (note the trailing colon).

# For example, on my Linux system, the SVG output options are:
$ dot -Tsvg:
Format: "svg:" not recognized. Use one of: svg:svg:core svg:cairo:cairo
# svg:svg:core is listed first, meaning it's the default for dot -Tsvg

# For JPEG, the options are:
$ dot -Tjpg:
Format: "jpg:" not recognized. Use one of: jpg:cairo:gdk jpg:cairo:gd
 jpg:gd:gd jpg:cairo:devil

So, if dot -Tjpg is giving me problems, I might suspect it's an issue with the cairo:gdk output plugin. I can try using the GD library's JPEG renderer, instead, by running dot -Tjpg:gd:gd graph.gv -o graph.jpg

A list of all the output formats available with the set of installed plugins can be queried by passing any invalid option to -T.

# For example, again on my Linux system with all Graphviz plugin libraries installed
$ dot -Thelp 2>&1 |fmt
Format: "help" not recognized. Use one of: bmp canon cmap cmapx cmapx_np
dot dot_json eps fig gd gd2 gif gv ico imap imap_np ismap jpe jpeg
jpg json json0 kitty kittyz pdf pic plain plain-ext png pov ps ps2 svg
svg_inline svgz tga tif tiff tk vrml vt vt-24bit vt-4up vt-6up vt-8up
wbmp webp x11 xdot xdot1.2 xdot1.4 xdot_json xlib

ferdnyc avatar Sep 17 '25 08:09 ferdnyc