diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index a195ff8c2..ec8301973 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -334,10 +334,13 @@ def _save_netpbm(im, fp, filename): import os from subprocess import Popen, check_call, PIPE, CalledProcessError + import tempfile file = im._dump() + if im.mode != "RGB": with open(filename, 'wb') as f: - check_call(["ppmtogif", file], stdout=f) + stderr = tempfile.TemporaryFile() + check_call(["ppmtogif", file], stdout=f, stderr=stderr) else: with open(filename, 'wb') as f: @@ -345,9 +348,11 @@ def _save_netpbm(im, fp, filename): # "ppmquant 256 %s | ppmtogif > %s" % (file, filename) quant_cmd = ["ppmquant", "256", file] togif_cmd = ["ppmtogif"] - quant_proc = Popen(quant_cmd, stdout=PIPE) - togif_proc = Popen(togif_cmd, stdin=quant_proc.stdout, stdout=f) - + stderr = tempfile.TemporaryFile() + quant_proc = Popen(quant_cmd, stdout=PIPE, stderr=stderr) + stderr = tempfile.TemporaryFile() + togif_proc = Popen(togif_cmd, stdin=quant_proc.stdout, stdout=f, stderr=stderr) + # Allow ppmquant to receive SIGPIPE if ppmtogif exits quant_proc.stdout.close()