Failing to import an .eps file

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

Import["dcl.eps"]


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?

-
Try Import["dcl.eps", "Binary"] – R Hall Aug 26 '13 at 19:47
@RHall It's working but I want the true image not numbers in binary form. The whole purpose is to rasterize the image. – Vaggelis_Z Aug 26 '13 at 19:51
Just prefix the Import with Image@ – R Hall Aug 26 '13 at 20:06
@RHall Do you mean Image@Import["dcl.eps", "Binary"]; – Vaggelis_Z Aug 26 '13 at 20:08
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? – cormullion Aug 26 '13 at 20:49

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:

 ImportString["%!PS-Adobe
%%BoundingBox: 0 0 300 300
newpath
100 200 moveto
200 250 lineto
100 300 lineto
closepath
gsave 0.5 setgray fill
grestore
4 setlinewidth 0.75 setgray
stroke
/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 :).

Mathematica can also execute simple procedural code:

ImportString["%!PS-Adobe
%%BoundingBox: 0 0 200 100
/csquare {
newpath
0 0 moveto
0 1 rlineto
1 0 rlineto
0 -1 rlineto
closepath
setrgbcolor
fill
} 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"]


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

ImportString["%!PS-Adobe
%%BoundingBox: 0 200 600 300
/pagewidth 350 def
/doCircle { xpos ypos radius 0 360 arc stroke} 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
showpage
", "EPS"]


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

ImportString["%!PS-Adobe
%%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
triangle
depth maxdepth lt
{
/newa a 2 div 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
}
if
} def
0 setlinewidth
/length 450 def
/xoff 30 def
/yoff 30 def
length xoff yoff 1 rec
showpage", "EPS"]


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

However...

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

ImportString["%!PS-Adobe
%%BoundingBox: 0 0 500 500
newpath
100 150 60 0 360 arc closepath stroke
newpath
200 250 60 0 180 arc closepath stroke
newpath
300 350 60 180 360 arc closepath stroke
", "EPS"]


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.

-
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 – Masi May 3 at 15:16