From b981ef425b27bf81930b9c5b775ca311c980aea8 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Sun, 29 Jun 2014 14:24:32 -0700 Subject: [PATCH] Suppress stderr from ppmquant and ppmtogif --- PIL/GifImagePlugin.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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()