Page 1 of 1

Error converting strange EPS format

Posted: 2015-07-29T15:45:28-07:00
by bearcherian
I have a large number of EPS files that need to be converted to JPG. These were created in Photoshop, but not in a standard method, at least it doesn't seem like. I installed ImageMagick with the Ghostscript delegate. When I run

Code: Select all

convert file.eps file.jpg
I get the following

Code: Select all

Error: /undefined in 3*F.XN6W
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1951   1   3   %oparray_pop   1950   1   3   %oparray_pop   --nostringval--   1934   1   3   %oparray_pop   1820   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1190/1684(ro)(G)--   --dict:0/20(G)--   --dict:87/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
Current file position is 43957
GPL Ghostscript 9.16: Unrecoverable error, exit code 1
Error: /undefined in 3*F.XN6W
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1951   1   3   %oparray_pop   1950   1   3   %oparray_pop   --nostringval--   1934   1   3   %oparray_pop   1820   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:1190/1684(ro)(G)--   --dict:0/20(G)--   --dict:87/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
Current file position is 43957
GPL Ghostscript 9.16: Unrecoverable error, exit code 1
I have a sample file here: https://www.dropbox.com/s/f2qtyqxkwu6g6 ... G.eps?dl=0

Re: Error converting strange EPS format

Posted: 2015-07-29T15:54:01-07:00
by fmw42
What IM version and platform? Identify -verbose fails for me on IM 6.9.1.10 Q16 Mac OSX and GS 9.10. Are you on a more recent version of GS? You error message seems to imply GS 9.16

Re: Error converting strange EPS format

Posted: 2015-07-29T15:59:50-07:00
by bearcherian
Yes, OSX, IM 6.9.1-10, GS 9.16. Freshly installed with Homebrew.

Re: Error converting strange EPS format

Posted: 2015-07-29T16:02:10-07:00
by bearcherian
I tried another EPS, this one shows the preview in Finder, and seems to be saved in a more standard format. That one worked, apart from the size being off. But no errors.

Re: Error converting strange EPS format

Posted: 2015-07-29T16:03:31-07:00
by bearcherian
Forgot to mention, identify fails and returns the same error as well

Re: Error converting strange EPS format

Posted: 2015-07-29T16:08:33-07:00
by fmw42
Sorry, it fails for me, also as above. One of the IM developers will have to look into the image data and meta data to see. Is this reproducible with other EPS images or only this one? That is can you save EPS images from PS and get this error always? If only this one image, then perhaps it is corrupt in some way? Can you reproduce the steps you took to create and save this image and still get the error?

Re: Error converting strange EPS format

Posted: 2015-07-29T16:10:48-07:00
by bearcherian
There are many of them. I have a sample of about a dozen, but there are hundreds more. I believe they were created in Photoshop CS5. Says format is 'image/epsf'.

These open up correctly in Photoshop, and are 8bit RGB files.

Re: Error converting strange EPS format

Posted: 2015-07-29T17:59:05-07:00
by 246246
Just a quick response.

I'm not sure it's a bug of GS, but your data is saved as jpg between beginimage and %%EndBinary

Code: Select all

beginimage
s4IA>!"M;*Ddm8XA3^+p!!3,S!/(=R!WiH*!sAZ,"9eo1"9eu5"U,&6#R:S>#6tMB

...
...

.])Ag?J)RnqI"F2Ki\Q4i)[o2m/?ch<M]eGPDZiiLqp':;\af^f`~>
%%EndBinary
So save everything between them to a file, and find ASCII85 decoder to convert it to jpg.
(It looks it also has a profile, consider it later.)

[Edit]
You can find many ASCII85 decoders from web:
https://en.wikipedia.org/wiki/Ascii85#External_links
Find suitable one for your environment.

I tested with pre-Compiled cygwin binary found at:
http://matsp888.no-ip.org/~mats/softwar ... 5-tools/c/
http://matsp888.no-ip.org/~mats/softwar ... ibascii85/

> a85decode infile outfile.jpg

that confirm your image is converted to jpeg.

Also online ascii85 decoder is here:
http://www.webutils.pl/index.php?idx=ascii85

Re: Error converting strange EPS format

Posted: 2015-07-29T18:05:04-07:00
by fmw42
Can you upload an example file to dropbox.com and put the URL here so some one can check it out?

Re: Error converting strange EPS format

Posted: 2015-07-29T18:40:30-07:00
by fmw42
You can also try using GS standalone. Perhaps it has more options than IM is currently using for EPSF format. If that works, then IM may need a fix or update.

Re: Error converting strange EPS format

Posted: 2015-07-29T19:53:53-07:00
by bearcherian
fmw42 wrote:Can you upload an example file to dropbox.com and put the URL here so some one can check it out?
Another example other than the one above?

Re: Error converting strange EPS format

Posted: 2015-07-29T20:17:38-07:00
by fmw42
bearcherian wrote:
fmw42 wrote:Can you upload an example file to dropbox.com and put the URL here so some one can check it out?
Another example other than the one above?
Sorry, I forgot about that file. Did you try using GS standalone?

Re: Error converting strange EPS format

Posted: 2015-07-30T00:18:13-07:00
by 246246
246246 wrote: You can find many ASCII85 decoders from web:
https://en.wikipedia.org/wiki/Ascii85#External_links
Find suitable one for your environment.

I tested with pre-Compiled cygwin binary found at:
http://matsp888.no-ip.org/~mats/softwar ... 5-tools/c/
http://matsp888.no-ip.org/~mats/softwar ... ibascii85/

> a85decode infile outfile.jpg
I noticed some decoder found there need '<~' at the beginning of input. (ASCII85 has some variations.)

a85decode mentioned above does not need it.

Code: Select all

$ tr '\015' '\012' < S_2505G.eps | sed -n -e '/^beginimage/,/^%%EndBinary/{//!p}' | ./a85decode > S_2505G.jpg
or if you download decode85.c from http://www.stillhq.com/extracted/ascii85/
and compile
$ clang decode85.c -o decode85

Code: Select all

$ tr '\015' '\012' < S_2505G.eps | (echo -n '<~'; sed -n -e '/^beginimage/,/^%%EndBinary/{//!p}') | ./decode85 > S_2505G.jpg
would work.

------
[Edit for later reference]

if you are trying awk version found https://sites.google.com/site/dannychou ... wk-scripts ,
-b option is required for current gawk, i.e.;

Code: Select all

$ tr '\015' '\012' < S_2505G.eps | (echo -n '<~'; sed -n -e '/^beginimage/,/^%%EndBinary/{//!p}') | awk -b -f ./b85 d > S_2505G.jpg
------

Both decoder generate jpeg from your eps.

$ identify.exe S_2505G.jpg
S_2505.jpg JPEG 2000x2000 2000x2000+0+0 8-bit sRGB 689KB 0.000u 0:00.000

It is of course a temporary workaround though (and may not work for your other file, especially if created in other ways.)

Re: Error converting strange EPS format

Posted: 2015-07-30T06:53:38-07:00
by 246246
Now I understand where your eps file is broken. It is not a bug of Ghostscript.
As I previously commented, data part is preserved with no problem.

See the flagment of your eps:

Code: Select all

/MetadataString 15961 string def % exact length of metadata
/TempString 100 string def
/ConsumeMetadata {
currentfile TempString readline pop pop
currentfile MetadataString readstring pop pop
} bind def
ConsumeMetadata
%begin_xml_packet: 8329

   ...

<?xpacket end="w"?>
%end_xml_packet
Calling ConsumeMetadata tries to skip 15961 bytes (which is defined as MetadataString).
But the real length of xml_packet is 8329 byte. That's why Ghostscript regard the midst of data part string as a kind of operator/operand.

If you rewrite 15961 in PostScript code to exact length 8329 (written in comment part), i.e.

Code: Select all

/MetadataString 8329 string def % exact length of metadata
/TempString 100 string def
/ConsumeMetadata {
currentfile TempString readline pop pop
currentfile MetadataString readstring pop pop
} bind def
ConsumeMetadata
%begin_xml_packet: 8329
all works fine.

If all broken files are likewise, making filter to fix it is relatively an easy job.

Re: Error converting strange EPS format

Posted: 2015-07-31T10:10:26-07:00
by bearcherian
Thanks, for the response. Been working on some other parts of this project, and i'm just getting back to this.

This is part of a larger Java application, so what I'm trying to do now is read in the file, compare the /MetadataString and %beginXMLPacket lines, fix the incorrect values, write out the new/fixed file and run that through ImageMagick. It worked manually, like you said, so hopefully i'll be able to get it right in Java.