diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index c6d449425..7f29ffe12 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -333,13 +333,20 @@ def _save_netpbm(im, fp, filename): # below for information on how to enable this. import os + from subprocess import Popen, check_call, PIPE file = im._dump() if im.mode != "RGB": - os.system("ppmtogif %s >%s" % (file, filename)) + with open(filename, 'wb') as f: + check_call(["ppmtogif", file], stdout=f) else: - os.system("ppmquant 256 %s | ppmtogif >%s" % (file, filename)) - try: os.unlink(file) - except: pass + with open(filename, 'wb') as f: + #TODO: What happens if ppmquant fails? + ppmquant_proc = Popen(["ppmquant", "256", file], stdout=PIPE) + check_call(["ppmtogif"], stdin=ppmquant_proc.stdout, stdout=f) + try: + os.unlink(file) + except: + pass # -------------------------------------------------------------------- diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index 8a06cf5a5..c159d61c3 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -360,12 +360,14 @@ class JpegImageFile(ImageFile.ImageFile): # ALTERNATIVE: handle JPEGs via the IJG command line utilities + import subprocess import tempfile import os f, path = tempfile.mkstemp() os.close(f) if os.path.exists(self.filename): - os.system("djpeg %s > '%s'" % (quote(self.filename), path)) + with open(path, 'wb') as f: + subprocess.check_call(["djpeg", self.filename], stdout=f) else: raise ValueError("Invalid Filename") @@ -608,8 +610,10 @@ def _save(im, fp, filename): def _save_cjpeg(im, fp, filename): # ALTERNATIVE: handle JPEGs via the IJG command line utilities. import os - file = im._dump() - os.system("cjpeg %s >%s" % (file, filename)) + import subprocess + tempfile = im._dump() + with open(filename, 'wb') as f: + subprocess.check_call(["cjpeg", tempfile], stdout=f) try: os.unlink(file) except: