MathGroup Archive 1994

[Date Index] [Thread Index] [Author Index]

Search the Archive

Generating GIF files from Mathematica Graphics.

  • To: mathgroup at christensen.Cybernetics.NET
  • Subject: [mg332] Generating GIF files from Mathematica Graphics.
  • From: twj (Tom Wickham-Jones)
  • Date: Wed, 14 Dec 1994 10:12:35 -0600


This is a function that will take a Mathematica graphics object
and write a gif file.  


GIFExport[ file_, g_] :=
	(Display["!rasterps -format ppm > tmp.ppm", g];
     Run["ppmtogif tmp.ppm > " <> file] ;
     DeleteFile[ "tmp.ppm"] ;
     g)

To work it requires the rasterps binary and the ppmtogif binary.  

The former is distributed with Unix, NeXT, and DOS versions of 

Mathematica.  MS-Windows users can obtain the DOS version from 

MathSource (0203-634).  There is at the moment no Macintosh 

version of rasterps.   The ppmtogif binary can be built from 

the Portable Bitmap Toolkit which is also available on MathSource 

(0205-355).   For this function to work the utility programs must 

be available to the shell that is invoked by the Run command.

One deficiency of this conversion is that rasterps does not make
very beautiful text.  It has one built-in bitmap font which is
used for all text. 



This is a sample session.


In[1]:= GIFExport[ file_, g_] :=
        (Display["!rasterps -format ppm > tmp.ppm", g];
     Run["ppmtogif tmp.ppm > " <> file] ;
     DeleteFile[ "tmp.ppm"] ;
     g)
                                

In[2]:= Plot[ Sin[x], {x,0,2}]

Out[2]= -Graphics-

In[3]:= GIFExport[ "file.gif", %]
ppmtogif: computing colormap...
ppmtogif: 2 colors found

Out[3]= -Graphics-

With the Portable Bitmap Toolkit similar strategies can be followed
to generate many other file formats, for example TIFF.

Tom Wickham-Jones
WRI





  • Prev by Date: Re: symbolic derivatives
  • Next by Date: Re: Plot curiousities ...
  • Previous by thread: tiff or gif
  • Next by thread: Combining pure functions