Question

I am running inkscape from a Gearman PHP process on *nix-like systems (OS X 10.6.8, Linux of varying flavours) to convert SVG images to either PNG or PDF. I use something like this (line breaks added here just for clarity):

/full/path/to/inkscape -z \
    --export-png=/path/to/output.png \
    --export-width=100 --export-height=100 \
    /path/to/input.svg

It works, but despite the -z flag ("Do not use X server") I get this in my console output (on OS X):

Setting Language: .UTF-8

(process:44699): Gtk-WARNING **: Locale not supported by C library.
    Using the fallback 'C' locale.
Xlib:  extension "RANDR" missing on display "/tmp/launch-WvcqRh/org.x:0".

This suggests to me that inkscape is loading more libraries than it needs to, and that it could be faster if it didn't try to connect to an X server. However, other than using the -z/--without-gui flag, I am not sure what to try. Performance on my dev machine is still sub-second (at least for trivial SVG files), but I'd like to clean this up if I can. Even if the best answer is just "suppress error output"!

Maybe if I turn off or reset a bash DISPLAY env var? I'm not at all familiar with X.

Was it helpful?

Solution

Yes, if you want to make your programs not find X at all, you can unset DISPLAY before launching the process.

You can also use Xvfb to "fake" an X server: http://en.wikipedia.org/wiki/Xvfb

You might also want to look at these tools:

Their source code is really small.

OTHER TIPS

Another way to suppress the output, while preserving the ability to respond to true errors, is to call Inkscape from Python.

import subprocess               # May want to use subprocess32 instead

cmd_list = [ '/full/path/to/inkscape', '-z', 
             '--export-png', '/path/to/output.png',
             '--export-width', 100,
             '--export-height', 100,
             '/path/to/input.svg' ]

# Invoke the command.  Divert output that normally goes to stdout or stderr.
p = subprocess.Popen( cmd_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE )

# Below, < out > and < err > are strings or < None >, derived from stdout and stderr.
out, err = p.communicate()      # Waits for process to terminate

# Maybe do something with stdout output that is in < out >
# Maybe do something with stderr output that is in < err >

if p.returncode:
    raise Exception( 'Inkscape error: ' + (err or '?')  )

On my Mac OS system, the crufty status messages (described by the original poster) end up in err. Plus, for a particular job that I ran, there is additional messaging that ends up in out:

Background RRGGBBAA: ffffff00
Area 0:0:339:339 exported to 100 x 100 pixels (72.4584 dpi)
Bitmap saved as: /path/to/output.png

(The input svg file had a size of 339 by 339 pixels.)

(echo foo.ai --export-plain-svg foo.svg) | DISPLAY= inkscape --shell

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top