[Image-SIG] Problem with eps

Roman Putanowicz putanowr at twins.pk.edu.pl
Wed Apr 21 06:35:54 EDT 2004


Hi All,

I looked at few recent messages but I could not search the archive
so please excuse me if this problem was already posted.

I have a problem with loading a eps file (in attachment) (python 2.2.1,
PIL 1.1.4)

The following script

import Image
im = Image.open('a.eps')
im.load()
print im.getbbox()

Fails with the message:

Traceback (most recent call last):
  File "ala.py", line 3, in ?
    im.load()
  File "/opt/lib/python2.2/site-packages/PIL/EpsImagePlugin.py",
    line 282, in load self.im = Ghostscript(self.tile, self.size, self.fp)
  File "/opt/lib/python2.2/site-packages/PIL/EpsImagePlugin.py",
              line 75, in Ghostscript
    im = Image.core.open_ppm(file)
IOError: error when accessing file


Looking at the code I  discovered that gs wasn't producing any output
for my file and went to an empirical fix:
  in EpsImagePlugin.py in function Ghostscript I added 
  the command to write 'showpage' at the end of the input
  (see the attachment).

Can somebody with more postscript knowledge confirm that this was a bug
 and that the fix is all right ?

Thanks in advance

Romek
-- 
    _/_/_/       _/     _/       _/_/_/_/_/    Roman Putanowicz 
  _/            _/     _/           _/         Inst.Comp.Meth.Civ.Eng.
 _/            _/     _/           _/          tel +48 12  628 2569
 _/_/_/racow   _/_/_/niversity of _/echnology  putanowr at twins.pk.edu.pl

-------------- next part --------------
A non-text attachment was scrubbed...
Name: a.eps
Type: application/postscript
Size: 3245 bytes
Desc: not available
Url : http://mail.python.org/pipermail/image-sig/attachments/20040421/70e66c8e/a.eps
-------------- next part --------------
def Ghostscript(tile, size, fp):
    """Render an image using Ghostscript (Unix only)"""

    # Unpack decoder tile
    decoder, tile, offset, data = tile[0]
    length, bbox = data

    import tempfile, os

    file = tempfile.mktemp()

    # Build ghostscript command
    command = ["gs",
               "-q",                    # quite mode
               "-g%dx%d" % size,        # set output geometry (pixels)
               "-dNOPAUSE -dSAFER",     # don't pause between pages, safe mode
               "-sDEVICE=ppmraw",       # ppm driver
               "-sOutputFile=%s" % file,# output file
               "- >/dev/tty 2>/dev/tty"]

    command = string.join(command)
    # push data through ghostscript
    try:
        gs = os.popen(command, "w")
        # adjust for image origin
        if bbox[0] != 0 or bbox[1] != 0:
            gs.write("%d %d translate\n" % (-bbox[0], -bbox[1]))
        fp.seek(offset)
        while length > 0:
            s = fp.read(8192)
            if not s:
                break
            length = length - len(s)
            gs.write(s)
# FIX for problems with no output from gs
        gs.write("showpage")
        gs.close()
        im = Image.core.open_ppm(file)
    finally:
        try: os.unlink(file)
        except: pass

    return im




More information about the Image-SIG mailing list