Bug 698272 - Ghostscript doesn't convert EPS
Summary: Ghostscript doesn't convert EPS
Status: RESOLVED INVALID
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PS Interpreter (show other bugs)
Version: 9.19
Hardware: PC Linux
: P4 major
Assignee: Ken Sharp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-07-19 06:58 UTC by Samuele Kaplun
Modified: 2017-07-20 03:26 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments
the file I am trying to convert (11.67 KB, image/x-eps)
2017-07-19 06:58 UTC, Samuele Kaplun
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Samuele Kaplun 2017-07-19 06:58:44 UTC
Created attachment 13989 [details]
the file I am trying to convert

As reported in: https://github.com/python-pillow/Pillow/issues/2615

If I execute:
gs -q -g553x475 -r72.000000x72.000000 -dBATCH -dNOPAUSE -sDEVICE=ppmraw -sOutputFile=/tmp/tmpwifcPN -c '0 0 translate' -f d15-120f10.eps

in order to convert an .eps file into a ppmraw (this command is executed indirectly by Python Pillow library) then nothing is produced in output.

I tried different variation of the arguments without ever obtaining an output in /tmp/tmpwifcPN
Comment 1 Ken Sharp 2017-07-19 07:04:53 UTC
EPS files are meant to be included in other PostScript programs by an application, they are not intended to be used on their own.

As such, EPS files are not permitted to use the 'showpage' operator which transfers the rendered image to the output file. Since your file (correctly) doesn't include a showpage, the rendered output is never written.

If you append a 'showpage' to your EPS file, or in any other way execute showpage after the EPS is interpreted, then the content will be rendered.
Comment 2 Samuele Kaplun 2017-07-19 07:19:34 UTC
Dear Ken,

thanks a lot for the prompt response. So the only way to have the output being produced is literally to append the string to the input file? Or is there some other way to concatenate it so that it can be run in one command without touching the input?

Best regards,
     Samuele
Comment 3 Ken Sharp 2017-07-19 07:43:51 UTC
There are other ways. You could use the EPS the way EPS files are intended to be used; load it into a document and print the total document to PostScript.

Or you could drop the -dBATCH and -dNOPAUSE from the command line, then at the 'GS>' interactive prompt, type showpage and then quit. Or you could create a file which only has the single word showpage in it, and then supply that as an additional file to be run after the EPS file, or you could use the -c and -f switches (after the input filename) to supply PostScript on the command line.

There may be other ways as well, but there's certainly no shortage.
Comment 4 Ray Johnston 2017-07-19 09:14:19 UTC
Note that -c showpage can be appended to your arguments:

gs -q -g553x475 -r72 -sDEVICE=ppmraw -o /tmp/tmpwifcPN d15-120f10.eps -c showpage

Note that -r72 is equivalent to: 
   -r72.000000x72.000000
and -o /tmp/tmpwifcPN is equivalent to: 
   -dBATCH -dNOPAUSE -sOutputFile=/tmp/tmpwifcPN
and -c "0 0 translate" does nothing.

If -c is used before the input file, then -f is needed before the input file,
otherwise it is optional (but still could be used)
Comment 5 Samuele Kaplun 2017-07-19 12:33:08 UTC
Dear Ken and Ray,

thank you both for the valuable suggestions. They are surely going to help solving the bug I have in Pyhon-Pillow!

Best regards,
    Samuele
Comment 6 Samuele Kaplun 2017-07-19 13:07:52 UTC
Was this feature introduced in some particular Ghostscript version?
I have sent a pull-request to the Pillow project simply adding the suggested "-c showpage" command, and it seems that Pillow's tests are now failing everywhere but on one particular distribution:
https://travis-ci.org/python-pillow/Pillow/builds/255403650?utm_source=github_status&utm_medium=notification
(which might very well be the one I am also having on my production).
Comment 7 Ken Sharp 2017-07-19 13:46:00 UTC
(In reply to Samuele Kaplun from comment #6)
> Was this feature introduced in some particular Ghostscript version?

Which feature ? The -c switch ? That's been around for a long time.

> I have sent a pull-request to the Pillow project simply adding the suggested
> "-c showpage" command, and it seems that Pillow's tests are now failing
> everywhere but on one particular distribution:
> https://travis-ci.org/python-pillow/Pillow/builds/
> 255403650?utm_source=github_status&utm_medium=notification
> (which might very well be the one I am also having on my production).

Perhaps the test files are not EPS files, or are not single files. If you add a showpage to a PostScript program you will get an extra (blank) page produced.

Beyond that, can't comment, I'd need to see the files.
Comment 8 Ken Sharp 2017-07-20 03:26:57 UTC
It only occurred to me last night, but Ghostscript is actually supposed to add an implicit 'showpage' when asked to render an EPS file. (this is non-standard, but useful, behaviour for a PostScript RIP)

So why doesn't it do so in this case ?

Well the answer is simple, this isn't a valid EPS file. In order to be an EPS file there are a number of rules which need to be followed, these cover which operators can be used, but also specify a number of comments which must be present.

In particular the EPS file must include something like this comment:

%!PS-Adobe-3.1 EPSF-3.0

which states that the file is a PostScript program (%!PS), conforms to version 3.1 of the Adobe Document Structure Convention, is an EPS file (EPSF) and conforms ot version 3.0 o the EPS specification.

The 'EPS' file supplied here instead has:

%!PS-Adobe-2.0

Which states that its a PostScript program, conforming to version 2.0 of the Document Structure Convention.

Note that comments are not required in any PostScript program and may be ignored by a conforming interpreter. They are, however, required for EPS files.

Since this declares itself as a PostScript program, and not an EPS file, Ghostscript treats it as such and does not add an implicit showpage.

If I modify the original file to use the EPS header instead, then Ghostscript does add the showpage.

So, in short, Ghostscript is doing everything its supposed to.