Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a Mathematica installation on a Linux server that is intended to be used for batch processing. Some of the things that will be processed will include rendering of graphics. However, if I use Export["/file/name.gif", graphicsobject], Mathematica wants to connect to an X server.

Yes, I can run Xvfb or similar, but this seems like inordinate overkill. Is this really the only option? Is there no way to get Mathematica to render to GIF (or PNG, or BMP, or TIFF, or whatever; I don't really care) without having an X server running?

Update:

I just ran this small program without an X server available:

s=Graphics[Sphere[]];
Do[
    Print[fmt];
    TimeConstrained[
        Export["/tmp/img-"<>fmt, s, fmt],
          10, Print["Timeout"] ],
  {fmt, $ExportFormats} ]

and found that the only files created that contained something other than just the text Graphics[Sphere[0, 0, 0]] or -Graphics- were DXF and JVX, both of which were very simple renderings without axes or labels or anything once anything remotely more complex was rendered.

share|improve this question
    
Two things come to mind - 1 ) try postscript and some linux tool to convert 2) rasterize the graphics and write your own raw pnm format file (pnm is an easy thing to write). I have code for the later someplace, but I'll wait to see if someone has a less painful solution before going there. –  george2079 Aug 21 '13 at 20:58
    
..(assuming Rasterize[] doesnt need the X server.. ) I have no way to check that.. –  george2079 Aug 21 '13 at 21:00
    
Export[]ing PostScript seems to require an X server as well. Is there another way to generate PS? And Rasterize[] requires the X server. –  wfaulk Aug 21 '13 at 22:26
    
I had hopes for ps (eps) since its basically the native graphics language. You might see if the content of the graphics matters, try some very simple 2d stuff with no fonts, etc. –  george2079 Aug 22 '13 at 15:50
    
Assuming Export["/tmp/circle.eps", Graphics[Circle[]]] is simple enough, still no joy. –  wfaulk Aug 22 '13 at 16:12

2 Answers 2

up vote 1 down vote accepted

I got this response from Wolfram support:

I understand you are wondering whether an X server is required to export to graphics files.

The answer is yes. Exporting to a raster format requires the front end, which in turn must be able to connect to an X server. You can accomplish this using X forwarding if you already have an X server working, or you can try setting up a virtual X server like Xvnc.

share|improve this answer

Found my raw pnm write code..

writepnm[raster_, file_] := Module[{maxval, flatdata, fmt, f},
  flatdata = Round[Flatten[raster] ];
  maxval = Max[flatdata];
  If[maxval > 255, 
    fmt = "UnsignedInteger16", 
    fmt = "UnsignedInteger8"];
  f = OpenWrite[file, BinaryFormat -> True];
  BinaryWrite[f, StringJoin[Riffle[Flatten@{"P6",
     ToString /@  Rest@Reverse@ Dimensions[raster] , 
     ToString[maxval]}, " "], {" "}], "TerminatedString" ];
  BinaryWrite[f, flatdata, fmt] ;
  Close[f];]

writepnm[Rasterize[Graphics3D[Sphere[]], "Data"], "test.pnm"]
share|improve this answer
    
Rasterize[] still requires an X server, unfortunately. –  wfaulk Aug 21 '13 at 22:22
    
i was afraid of that. –  george2079 Aug 21 '13 at 22:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.