From b8070d388f2b044491bd00c56074dea760b745a9 Mon Sep 17 00:00:00 2001 From: Jens Hedegaard Nielsen Date: Fri, 10 Jul 2015 13:29:56 -0500 Subject: [PATCH] Make sure pil files are closed correctly Silence warnings in some tests --- lib/matplotlib/image.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 686f5d928424..22a5c24d3aa3 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -1259,8 +1259,10 @@ def pilread(fname): from PIL import Image except ImportError: return None - image = Image.open(fname) - return pil_to_array(image) + with open(fname, 'rb') as f: + image = Image.open(f) + array = pil_to_array(image) + return array handlers = {'png': _png.read_png, } if format is None: