Python: PIL - [Errno 32] Broken pipe when saving .png

What I'm trying to do here is save the contents of Tkinter Canvas as a .png image using PIL.

This is my save function ('graph' is a canvas).

def SaveAs(): filename = tkFileDialog.asksaveasfilename(initialfile="Untitled Graph", parent=master) graph.postscript(file=filename+".eps") img = Image.open(filename+".eps") img.save(filename+".png", "png") 

But he gets this error:

 Exception in Tkinter callback Traceback (most recent call last): File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__ return self.func(*args) File "C:\Users\Adam\Desktop\Graphing Calculator\Graphing Calculator.py", line 352, in SaveAs img.save(filename+".png", "png") File "C:\Python27\lib\site-packages\PIL\Image.py", line 1406, in save self.load() File "C:\Python27\lib\site-packages\PIL\EpsImagePlugin.py", line 283, in load self.im = Ghostscript(self.tile, self.size, self.fp) File "C:\Python27\lib\site-packages\PIL\EpsImagePlugin.py", line 72, in Ghostscript gs.write(s) IOError: [Errno 32] Broken pipe 

I am running this on Windows 7, Python 2.7.1.

How do I do this job?

+4
source share
3 answers

Oh, I just get the same error. I decided it now

just follow these steps after installing PIL and Ghostscript

1) Open C: \ Python27 \ Lib \ site-packages \ PIL \ EpsImagePlugin.py 2) Change the code near line 50 so that it looks like this:

Create ghostscript command

 command = ["gswin32c", "-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 "-" ] 

Make sure gswin32c.exe is in PATH

luck

+5
source

It seems that the Ghostscript executable is an error and then closes the connection . Others had the same problem on different OSs .

So, first, I would recommend that you confirm the correct installation of PIL - see frequently asked questions for tips. Then make sure Ghostscript is up and running. Finally, make sure Python can find Ghostscript, for example, by running a PIL script that works elsewhere.

Oh, also - here are some tips for detecting a broken pipeline error , so your program may be more stable, recognize the problem and warn the end user, I hope this helps!

+2
source

I realized that although Python 2.7 has this EPEImagePulgin.py, Anaconda also has it. And unfortunately, the Anaconda file is an older version. And unfortunately, when you start your Spyder environment, it collects the epsimageplugin.py file from the anaconda folder.

Thus, I got a similar pipe break error.

When I went into the python 2.7 directory and opened the python console and then ran my code, it went fine.

Since the lates file epsimageplugin.py takes into account the Windows environment and the corresponding ghostscript exe files. Hope this helps.

+1
source

All Articles