I have an .eps file which was created using GLE. There is nothing wrong with the file, GS View can read it correctly. However, when I use Mathematica to read it using


it returns $Failed. The particular .eps file can be found here EPS file

I want to read this eps file so as to rasterize it, thus reducing its size. I'm using Mathematica v 9.0 under Win XP.

Any ideas why Mathematica cannot read this file?

  • $\begingroup$ Try Import["dcl.eps", "Binary"] $\endgroup$ Commented Aug 26, 2013 at 19:47
  • $\begingroup$ @RHall It's working but I want the true image not numbers in binary form. The whole purpose is to rasterize the image. $\endgroup$
    – Vaggelis_Z
    Commented Aug 26, 2013 at 19:51
  • $\begingroup$ Just prefix the Import with Image@ $\endgroup$ Commented Aug 26, 2013 at 20:06
  • $\begingroup$ @RHall Do you mean Image@Import["dcl.eps", "Binary"]; $\endgroup$
    – Vaggelis_Z
    Commented Aug 26, 2013 at 20:08
  • 1
    $\begingroup$ I think you have to pass this file through a PostScript interpreter to see the image. It looks like a JPEG image, encoded so as to fit inside an EPS file. I don't think Mathematica interprets PostScript commands? $\endgroup$
    – cormullion
    Commented Aug 26, 2013 at 20:49

1 Answer 1


An EPS (Encapsulated PostScript) file contains executable PostScript code. Most applications don't attempt to interpret or run this code when 'importing' or 'placing' an EPS file. The EPS object is usually treated like any other JPG or PNG image, and sits there, looking pretty (if it has a preview). Only when the document is sent to a real (or virtual) printer is the PostScript code inside the file executed to produce graphical output.

However, unlike most applications, Mathematica executes the PostScript code when you import the file. To find out how much of the PostScript language Mathematica understands, it's possible to do some experiments using ImportString (which is easier than writing files). Here's a simple list of PostScript commands:

 %%BoundingBox: 0 0 300 300
 100 200 moveto
 200 250 lineto
 100 300 lineto
 gsave 0.5 setgray fill
 4 setlinewidth 0.75 setgray
 /Times-Roman findfont 48 scalefont setfont
 1 .5 .1 0 setcmykcolor
 20 100 moveto
 (Hello!) show", "EPS"]

This sequence of graphic commands is interpreted correctly — even the top corner is clipped - my mistake there :).

simple graphics commands

Mathematica can also execute simple procedural code:

 %%BoundingBox: 0 0 200 100
 /csquare {
    0 0 moveto
    0 1 rlineto
    1 0 rlineto
    0 -1 rlineto
 } def

 10 10 scale

 5 5 translate
 1 0 0 csquare

 1 0 translate
 0 1 0 csquare

 1 0 translate
 0 0 1 csquare
 ", "EPS"]

procedural graphics

And there are no problems with this sort of thing either:

 %%BoundingBox: 0 200 600 300
 /pagewidth 350 def
 /doCircle { xpos ypos radius 0 360 arc stroke} def
 /increase-x { xpos radius add /xpos exch def} def
 /lineofcircles { /ypos exch def
      /radius exch def /xpos 50 def
      { xpos pagewidth le
      { doCircle increase-x}
      { exit } ifelse
      } loop
 } def
 30 250 lineofcircles
 1 .3 .4 setrgbcolor
 20 250 lineofcircles
 .2 .5 .2 setrgbcolor
 10 250 lineofcircles
 ", "EPS"]

more complex

It's possible to run recursive code, such as this famous example:

 %%BoundingBox: 0 0 500 500
 % Sierpinski gasket By John Fouhy.
 /maxdepth 12 def
 /root3 1.7320508 def
 /triangle { newpath x y moveto a 0 rlineto 120 rotate a 0 rlineto 
240 rotate closepath stroke } def
 /rec {
   % usage: a x y depth rec
   % where a is the side length, (x,y) are the coords of the lower
   % left corner, and depth is the recursion depth
 /depth exch def
 /y exch def /x exch def /a exch def
 depth maxdepth lt
 /newa a 2 div def
 /newdepth depth 1 add def
 newa x y newdepth
 newa x a 4 div add y root3 a mul 4 div add newdepth
 newa x newa add y newdepth rec rec rec
 } def
 0 setlinewidth
 /length 450 def
 /xoff 30 def
 /yoff 30 def
 length xoff yoff 1 rec
 showpage", "EPS"]

sierpinski gasket

Admittedly, this is not a very useful feature (Mathematica programming is more fun than PostScript-stack-wrangling), but it's still cool.


It doesn't take long to find things that don't work, either visibly or which fail silently. Here's a simple example:

 %%BoundingBox: 0 0 500 500
 100 150 60 0 360 arc closepath stroke
 200 250 60 0 180 arc closepath stroke
 300 350 60 180 360 arc closepath stroke
 ", "EPS"]

dodgy arcs

and arcn (for drawing arcs in the opposite direction - important for making holes!) isn't available at all. Mathematica doesn't support every aspect of the language, although it's hard to find out what is supported and what isn't.

To address the question... Mathematica does support the image operator, for converting string data to a raster image. However, in the original file (dcl.eps), line 17 refers to currentfile. A full PostScript interpreter would read the data from the input file (lines 35 to the end), but this operator isn't supported — so the data never gets read.

So the unanswered question is how to find out how much of the PostScript language is supported by Mathematica. Perhaps someone from Wolfram has the inside story.

  • $\begingroup$ Does your answer say that the only way to import .eps image is to rasterise it for instance to .ps? So .ps is only supported here as the rasterized image. I extended the thread here stackoverflow.com/q/37007587/54964 $\endgroup$ Commented May 3, 2016 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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