batik-rasterizer.jar - convert svg to png

2019-04-16 17:04发布

I was try yo setup an export server in my linux server with the following command to download graph as image from Highcharts.

$command = "java -jar batik-rasterizer.jar -m image/png -d temp/1a6b5dd08ec607454b81f91097fb24a6.png temp/1a6b5dd08ec607454b81f91097fb24a6.svg 2>&1 "; 
$output = shell_exec($command);
echo "Command: $command <br>";
echo "Output: $output";

It creates an image in my local windows machine perfectly ,But i uploaded it in my linux server,I am getting errors.

 About to transcode 1 SVG file(s) Converting 1a6b5dd08ec607454b81f91097fb24a6.svg to temp/1a6b5dd08ec607454b81f91097fb24a6.png ... (.:21519): Gtk-WARNING **: cannot open display:

Why this happens?

And i notice that an image is created with 0 kb invalid image

Note: I have also tried the following methods.

1)folder containing batik-rasterizer.jar and the files have owner as root and permission is set as 777.

2)i also try to execute it with /user/bin/java , which java insted pf java command.

3)I also try to execute this command as root using terminal using putty,Java is installed in my server.

1条回答
Root(大扎)
2楼-- · 2019-04-16 18:05

Execute java with the -Djava.awt.headless=true command-line option:

$command = "java -Djava.awt.headless=true -jar batik-rasterizer.jar -m image/png -d temp/out.png temp/in.svg 2>&1 "; 

Update

If passing the additional command-line option still does not yield the expected result, check your Java version. Updating your JRE to a more recent version (1.7) might also resolve the issue.

查看更多
登录 后发表回答