language lawyer needed: PIL fails on Adobe Illustrator EPS...

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

language lawyer needed: PIL fails on Adobe Illustrator EPS...

jalopyuser
I think I need a language lawyer.  I'm finding that PIL 1.1.7 can't
import EPS files output by Adobe Illustrator.  It chokes on the
following sequence of lines in the header:

%!PS-Adobe-3.0 EPSF-3.0
%%Creator: Adobe Illustrator(R) 8.0
%%AI8_CreatorVersion: 13.0.0
%%For: (Administrator) ()
%%CreationDate: 8/20/2008 6:47 PM
%%BoundingBox: 0 0 2801 2801
%%HiResBoundingBox: 0 0 2800.5 2800.5
%%DocumentProcessColors: Cyan Magenta Yellow Black
%%DocumentSuppliedResources: procset Adobe_level2_AI5 1.2 0
%%+ procset AGM_Gradient 1.0 0
%%+ procset Adobe_ColorImage_AI6 1.3 0
%%+ procset Adobe_Illustrator_AI5 1.3 0
%%+ procset Adobe_pattern_AI5 1.0 0
%%+ procset Adobe_cshow 2.0 8
%%+ procset Adobe_shading_AI8 1.0 0
%AI5_FileFormat 4.0
%AI3_ColorUsage: Color
%AI3_IncludePlacedImages
[...]

When I look at it with pdb, the problem seems to be the %AI5 and %AI3
lines -- they don't match the header line template, though I believe
they are valid Postscript comments:

(Pdb) !Image.open("/project/uplib/samples/postscript/badfoo.eps")
!Image.open("/project/uplib/samples/postscript/badfoo.eps")
*** IOError: bad EPS header
(Pdb) l
201                      if k[:8] == "PS-Adobe":
202                          self.info[k[:8]] = k[9:]
203                      else:
204                          self.info[k] = ""
205                  else:
206  ->                    raise IOError, "bad EPS header"
207  
208              s = fp.readline()
209  
210              if s[:1] != "%":
211                  break
(Pdb) p s
'%AI3_ColorUsage: Color'
(Pdb) field
<_sre.SRE_Pattern object at 0x4798a0>
(Pdb) field.match(s)
(Pdb) ^D

So, are Postscript comments allowed in the DSC headers?  That is, is
this a PIL bug or an Illustrator bug.

Bill
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: language lawyer needed: PIL fails on Adobe Illustrator EPS...

Fredrik Lundh
Haven't checked the DSC spec in ages, but given your observation, it'd
probably make sense to skip all non-DSC comments no matter what the
spec actually says.  Can you provide a patch (or a sample file)?

</F>

On Sat, Mar 20, 2010 at 11:13 PM, Bill Janssen <[hidden email]> wrote:

> I think I need a language lawyer.  I'm finding that PIL 1.1.7 can't
> import EPS files output by Adobe Illustrator.  It chokes on the
> following sequence of lines in the header:
>
> %!PS-Adobe-3.0 EPSF-3.0
> %%Creator: Adobe Illustrator(R) 8.0
> %%AI8_CreatorVersion: 13.0.0
> %%For: (Administrator) ()
> %%CreationDate: 8/20/2008 6:47 PM
> %%BoundingBox: 0 0 2801 2801
> %%HiResBoundingBox: 0 0 2800.5 2800.5
> %%DocumentProcessColors: Cyan Magenta Yellow Black
> %%DocumentSuppliedResources: procset Adobe_level2_AI5 1.2 0
> %%+ procset AGM_Gradient 1.0 0
> %%+ procset Adobe_ColorImage_AI6 1.3 0
> %%+ procset Adobe_Illustrator_AI5 1.3 0
> %%+ procset Adobe_pattern_AI5 1.0 0
> %%+ procset Adobe_cshow 2.0 8
> %%+ procset Adobe_shading_AI8 1.0 0
> %AI5_FileFormat 4.0
> %AI3_ColorUsage: Color
> %AI3_IncludePlacedImages
> [...]
>
> When I look at it with pdb, the problem seems to be the %AI5 and %AI3
> lines -- they don't match the header line template, though I believe
> they are valid Postscript comments:
>
> (Pdb) !Image.open("/project/uplib/samples/postscript/badfoo.eps")
> !Image.open("/project/uplib/samples/postscript/badfoo.eps")
> *** IOError: bad EPS header
> (Pdb) l
> 201                         if k[:8] == "PS-Adobe":
> 202                             self.info[k[:8]] = k[9:]
> 203                         else:
> 204                             self.info[k] = ""
> 205                     else:
> 206  ->                     raise IOError, "bad EPS header"
> 207
> 208                 s = fp.readline()
> 209
> 210                 if s[:1] != "%":
> 211                     break
> (Pdb) p s
> '%AI3_ColorUsage: Color'
> (Pdb) field
> <_sre.SRE_Pattern object at 0x4798a0>
> (Pdb) field.match(s)
> (Pdb) ^D
>
> So, are Postscript comments allowed in the DSC headers?  That is, is
> this a PIL bug or an Illustrator bug.
>
> Bill
> _______________________________________________
> Image-SIG maillist  -  [hidden email]
> http://mail.python.org/mailman/listinfo/image-sig
>
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: language lawyer needed: PIL fails on Adobe Illustrator EPS...

jalopyuser
Fredrik Lundh <[hidden email]> wrote:

> Haven't checked the DSC spec in ages, but given your observation, it'd
> probably make sense to skip all non-DSC comments no matter what the
> spec actually says.

Yes, I agree.

> Can you provide a patch (or a sample file)?

Yes, I think so.

Bill
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: language lawyer needed: PIL fails on Adobe Illustrator EPS...

jalopyuser
In reply to this post by Fredrik Lundh
Here you go.

Bill

--- Imaging-1.1.7/PIL/EpsImagePlugin.py 2009-10-31 17:44:11.000000000 -0700
+++ modImaging/PIL/EpsImagePlugin.py 2010-03-21 11:32:54.000000000 -0700
@@ -202,6 +202,12 @@
                         self.info[k[:8]] = k[9:]
                     else:
                         self.info[k] = ""
+
+                elif s[0] == '%':
+                    # handle non-DSC Postscript comments that some
+                    # tools mistakenly put in the Comments section
+                    pass
+
                 else:
                     raise IOError, "bad EPS header"
 
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig