55

Is there any command line (pipeable) graph viewer for SVG, JPG, and PNG images?

I'm particularly looking for a way to pipe the graphs/images to the program, instead of using files, so there must be an option to specify the file type/extension.

Though gv works for PS/PDF generated by dot programs, I'd like to know whether there are alternatives for supporting SVG image files.

Matthias Braun
  • 1,162
  • 1
  • 17
  • 29
Lenik
  • 17,942
  • 25
  • 87
  • 119
  • 1
    just to clarify: your main point is not to display the .svg, .jpg and .png on the console ("command line"), but rather to pipe such mime-types to a normal graphical program? – akira Aug 11 '10 at 05:29
  • 1
    Yes I'd want to display in X. Just like gv does. But gv doesn't support SVG, etc. – Lenik Aug 11 '10 at 09:11
  • `gwenview` quite fast, wonder if meets your needs? – Aquarius Power Jul 02 '17 at 01:16
  • 2
    eye-of-gnome (eog) shows svg files. Your browser (e.g. chromium) can also show svg files. I mostly do `chromium *.svg` to view my SVGs – Farid Cheraghi Jun 27 '20 at 23:22

10 Answers10

50

Have you tried the display program that comes with ImageMagick?

Dennis Williamson
  • 106,229
  • 19
  • 167
  • 187
  • 5
    AFAIK, Imagemagick alone can't display SVG files, it needs a tool that converts SVG to bitmap. On Debian, `sudo aptitude install librsvg2-bin` is necessary if "rsvg-convert" isn't installed yet. The package also contains a viewer `rsvg-view-3` that has better zoom than `display`. – Mytskine Dec 08 '12 at 17:25
  • 2
    @Mytskine: According to the [ImageMagick Documentation](http://www.imagemagick.org/script/formats.php#supported), it will use its own internal SVG renderer if [Inkscape](http://www.inkscape.org/) or [RSVG](http://developer.gnome.org/rsvg/) aren't available. – Dennis Williamson Dec 09 '12 at 02:46
  • 3
    On my system: `inkscape` is slow to load, `inkview` is fast but cannot seem to change view? `display` works great for me :-) – Hugh Perkins Jul 09 '15 at 00:12
  • I did not manage to get inkview work from pipe input, but display does exactly what I want anyway :-) I use it like `go run my_svg_generator.go | display` thx. – JepZ Jan 01 '17 at 18:40
  • 4
    WARNING!!!! do not use display if you are in a hurry!!! for a 500kb svg file (of analyzing systemd boot problems), it took 20min before I could use my machine again, as it used 4GB (requested 7GB of virt.mem) of my 6GB already bloated RAM and was swapping a huge lot (5GB went to swap only because of display) :(, not sure about performance of any other option to visualize svg tho., `gwenview` quite fast btw – Aquarius Power Jul 02 '17 at 01:16
  • 1
    @HughPerkins: For me (Arch Linux), `inkview` can zoom by just changing the size of the window, and change to the next image by space bar/ arrow keys. – Golar Ramblar Apr 06 '20 at 13:26
  • @Mytskine rsvg-view-3 is deprecated and remove from rsvg and hence IM display cannot rely on it to display svg files. [src](https://people.gnome.org/~federico/blog/removing-rsvg-view.html) – Farid Cheraghi Jun 28 '20 at 00:59
24

Inkscape already comes with its own viewer: inkview

It lacks features, it might be a bit slow, but it works (and probably renders SVG more accurately than ImageMagick's display).

Denilson Sá Maia
  • 12,863
  • 12
  • 40
  • 44
  • Just wanted to note that I tried `inkview` (I believe from 0.48 inkscape) on Ubuntu 10.04.3, started up amazingly fast! (EDIT: but only for small `.svg`s; try `inkview /usr/share/inkscape/examples/*.svg*` as the man page says, there are some heavies there too... Still, GUI startup _is_ fast.) Thanks for that note, @DenilsonSá - cheers! – sdaau May 20 '12 at 10:33
  • 2
    For really large SVGs, inkview appears to break. – CMCDragonkai Nov 23 '18 at 02:02
  • I had an SVG 32000 wide (yes, 32k pixels wide), `inkscape` showed it just fine, `display` could not load it. – Oliver Apr 30 '20 at 12:31
  • One drawback of inkview is that it cannot autoreload if the svg file changes. While `display` has the `-update 1` option, which autoreloads. I've tried to work around it by combining `inkview` with `entr`, but it's kinda wonky. – Steve Chavez Oct 17 '21 at 00:52
  • Installed inkscape on mac using Homebrew (brew install --cask inkscape) but don't see "inkview" command bundled along with it. Does it not come with homebrew installation or any other ways to install it – Naga Kiran Sep 10 '22 at 06:38
  • @NagaKiran I don't use Mac nor homebrew, but I downloaded the [Inkscape-1.2.1_x86_64.dmg](https://media.inkscape.org/dl/resources/file/Inkscape-1.2.1_x86_64.dmg) file and indeed it doesn't include the `inkview` binary, only `inkscape`. – Denilson Sá Maia Sep 12 '22 at 11:16
  • @DenilsonSáMaia any other ways to get `inkview` binary on Mac? – Naga Kiran Sep 12 '22 at 12:12
15

I usually work with SVG as text files, so would like the viewer to automatically refresh the display as soon as the file got saved (and its contents got changed) - this should be applicable to 'pipable' situations, I think (i.e. with named pipes).

Note that, for default Gnome apps:

  • evince currently works like this for PDFs, but seemingly it cannot read SVG (for me it generates "Unable to open document - Error opening file: Permission denied" when I tried to load SVG files)
  • eog (Eye Of Gnome) - the latest versions - can also detect if a file changed on this, and then offer a 'Reload' button; but apparently, you'd still have to click on 'Reload' each time (I cannot see a way to cause automatic reload always on file change in eog, like evince behaves with PDFs) - and also, at least on my Ubuntu 10.04, eog SVG support is somewhat broken (zoom in results with blurry lines)
  • ImageMagick's display not only does not automatically refresh when the file changes on disk - and even when you press 'refresh' in display, you still do not get the latest version of the file (meaning, you have to restart display to show the latest version :( ).

Here are some more notes I found so far:

  • Squiggle, the SVG Browser The SVG browser that is part of the Batik toolkit. - Download Batik batik-1.7.zip; unpack it; run java -jar batik-squiggle.jar and there it is; does not refresh the image automatically if the svg file changed on disk
  • SVG Image Viewer? - Ubuntu Forums recommendations:
    • In post #8 - "I wrote a little python script ... You just run it as: svg_compare.py and it opens up an svg and displays it using an svg library and using gtk's raster library. You can zoom with the mouse..."
    • xsvg (from http://cairographics.org) - I installed libsvg1_0.1.4-1_i386.deb, libsvg-cairo1_0.1.6-5_i386.deb and xsvg_0.2.1-3_i386.deb in that order; those versions are from 2005, and so xsvg is extremely simple - no zoom, nothing.. And needless to say, it does not react to saved file changes automatically...
  • through that, I found rsvg-view, which I think is a part of sudo apt-get install librsvg2-bin. Its small, nice, supports stdin - however, also rsvg-view cannot detect a file change, and automatically refresh on it..

Yup - well, I hope this helps...
Cheers!

 

EDIT (Dec 24 '10): well, here is also my contribution: svg_refreshview.py - which is basically a rework of svg_compare.py mentioned above, that simply shows an SVG file, and reloads the file and refreshes the display if the file has been modified. (it can't really work with stdin - but there are other scripts in my repo that parse stdin in python, maybe they'll help).

EDIT2 (May 20 '12): Also, came up with a Perl-Tk script example, which is very crude (no mouse interaction, no nothing), but uses ImageMagick Perl API, and so can render SVG (as bitmap on a canvas), please see answer #10670039 - ImageMagick API for command-line GUI application interface to display - Stack Overflow.

sdaau
  • 5,316
  • 8
  • 60
  • 77
  • 1
    It's so occasionally, I have patched the `Reload` stuff of `eog` JUST YESTERDAY! I hate that button, too! – Lenik Dec 24 '10 at 14:02
  • And, tell you another truth, the `display` comes from `ImageMagick` doesn't scale SVG well, because it rasterized the graph before display it. And even worse, `display` and `rsvg` doesn't work with some of my SVG files. Till now, only FireFox renders correctly. FireFox beats all. – Lenik Dec 24 '10 at 14:11
  • Hi @谢继雷, thanks for the comments! Well - I have just edited my post and added a link to a python script I just put together - try it out, maybe it helps... Cheers! Also +1 on the "hate that button" :) [although, I must admit: I'd always rather have a button to do something manually - than **not** to have it :) ... I'd just like auto-refresh extra :) ] – sdaau Dec 24 '10 at 14:17
11

What do you mean with 'pipe-able'?
feh is very good commandline viewer with tons of options.

Ivan Petrushev
  • 1,719
  • 4
  • 16
  • 28
  • 1
    I mean it accepts input from stdin, and guess the MIME type if possible. Or by specify the extension explicitly if it can't guess the file type heuristically. – Lenik Aug 11 '10 at 09:16
  • 15
    `feh` does not seem to support SVG at all; I get "`feh WARNING: pySVGLogo.svg - No Imlib2 loader for that file format`"... Cheers! – sdaau Dec 24 '10 at 10:56
  • 1
    Few more notes: first, `feh` [homepage](http://feh.finalrewind.org/), [examples](http://feh.finalrewind.org/examples/) and [screenshots](http://linux.softpedia.com/progScreenshots/feh-Screenshot-420.html); second (_ubuntu 10.04.3_): starts up very fast; has Debian/Ubuntu package; has a bit weird mouse interaction (see `feh --help` at end); I can load a directory of `png`s, and keep `←` or `→` (arrow keys) pressed, it loads so fast it looks like (or better than) an animated .gif `:)` ... Cheers! – sdaau May 20 '12 at 09:14
  • 2
    @sdaau, feh indeed does *not* support SVG, so is not a useful answer to the OP. – Dylan Thurston Jun 23 '19 at 17:56
  • `feh` supports SVG if `imagemagick` is installed: "If the convert binary (supplied by ImageMagick) is available, it also has limited support for many other file types, such as svg" — https://man.finalrewind.org/1/feh/ EDIT: However, I can't get it to work. – lindhe Jan 18 '20 at 19:08
  • 2
    To use feh you need to install imagemagick, and also specific a timeout on the feh command line, such as "--conversion-timeout 30" – GregD Jun 07 '20 at 17:23
6

I second Dennis Williamson's recommendation of ImageMagick display.

Also, you can sometimes use named pipes to pipe data to programs which read from a file.

Example:

mkfifo /tmp/foo.svg
cat /usr/share/inkscape/clipart/tux.svg > /tmp/foo.svg & inkscape /tmp/foo.svg
rm -f /tmp/foo.svg

Won't work with programs which expect to be able to seek backward in the file, though.

Jukka Matilainen
  • 2,792
  • 1
  • 18
  • 9
  • This usage of named pipe is very creative, thanks. After a try, I found it took a while to startup, it's a full functional editor rather than a simple viewer. – Lenik Aug 11 '10 at 09:25
  • Very cool usage of named pipes, this is a good example and also opened me up to many more possibilities outside of the scope of this question. Nice one. – user789517 Jun 12 '22 at 19:12
5

You can use feh which is very fast.

here is the man feh

SUPPORTED FORMATS
     feh can open any format supported by Imlib2, most notably jpeg, png, pnm, tiff, and bmp. The gif format is also supported, but only for static images. In case of animations, only the first frame will be shown.  If the
     convert binary (supplied by ImageMagick) is available, it also has limited support for many other filetypes, such as svg, xcf and otf. Use --magick-timeout num with a non-negative value to enable it.

which says if you want to open a SVG file you should use: --magick-timeout num and num can be a positive number line 1.

So the usage should be look like this: feh --magick-timeout 1 file.svg

here is a screenshot of opening a SVG file

enter image description here

Shakiba Moshiri
  • 231
  • 2
  • 6
4

It seems Geeqie viewer handles svg graphics and it automatically loads the updated images. I don't know whether it can take images from stdin. I hope it helps.

terdon
  • 52,568
  • 14
  • 124
  • 170
Ray
  • 329
  • 3
  • 3
1

If you for some reason really really don't want to use a temporary file, you might at least use a named-pipe.

With it you can easily use Firefox and it -- by far -- outperforms Inkscape's inkview, imagemagick's display, etc.

# Shell 1
mkfifo /tmp/mypipe
long | chain | of | stuff > /tmp/mypipe

# Shell 2
firefox --new-window /tmp/mypipe
Suuuehgi
  • 207
  • 1
  • 6
1

imv

The image viewer imv supports SVGs as well. It currently has no support for animations inside SVG, though.

Quoting from imv's project page, these are some of its features:

  • Native Wayland and X11 support
  • Support for dozens of image formats including:
    • PNG
    • JPEG
    • Animated GIFs
    • SVG
    • TIFF
    • Various RAW formats
    • Photoshop PSD files
  • Configurable key bindings and behaviour
  • Highly scriptable with IPC via imv-msg
Matthias Braun
  • 1,162
  • 1
  • 17
  • 29
0

I ended up on this question and I ultimately solved it with some mix and match. The reason I wanted this was to see which SVG I would like to pick for my Emacs icon (you can change it with anything else you want). Note the following two commands are doing the same thing but one uses fd and the other uses find:

# using fd (https://github.com/sharkdp/fd)
fd -a -e .svg emacs -X feh --conversion-timeout 5 {}
# using the GNU find
find /usr/share/icons -iname "*emacs*.svg" -exec feh --conversion-timeout 5 {} +

I hope this would save some time for people who end up here.