|
From: <jo...@us...> - 2010-10-04 18:46:24
|
Revision: 8727
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8727&view=rev
Author: jouni
Date: 2010-10-04 18:46:18 +0000 (Mon, 04 Oct 2010)
Log Message:
-----------
Fix JPEG saving bug: only accept the kwargs documented by PIL for JPEG files.
Modified Paths:
--------------
trunk/matplotlib/CHANGELOG
trunk/matplotlib/lib/matplotlib/backend_bases.py
trunk/matplotlib/lib/matplotlib/cbook.py
trunk/matplotlib/lib/matplotlib/tests/test_cbook.py
Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG 2010-10-03 21:24:46 UTC (rev 8726)
+++ trunk/matplotlib/CHANGELOG 2010-10-04 18:46:18 UTC (rev 8727)
@@ -1,3 +1,6 @@
+2010-10-04 Fix JPEG saving bug: only accept the kwargs documented
+ by PIL for JPEG files. - JKS
+
2010-09-15 Remove unused _wxagg extension and numerix.h. - EF
2010-08-25 Add new framework for doing animations with examples.- RM
Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backend_bases.py 2010-10-03 21:24:46 UTC (rev 8726)
+++ trunk/matplotlib/lib/matplotlib/backend_bases.py 2010-10-04 18:46:18 UTC (rev 8727)
@@ -1784,7 +1784,9 @@
agg = self.switch_backends(FigureCanvasAgg)
buf, size = agg.print_to_buffer()
image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
- return image.save(filename_or_obj, **kwargs)
+ options = cbook.restrict_dict(kwargs, ['quality', 'optimize',
+ 'progressive'])
+ return image.save(filename_or_obj, **options)
print_jpeg = print_jpg
filetypes['tif'] = filetypes['tiff'] = 'Tagged Image File Format'
Modified: trunk/matplotlib/lib/matplotlib/cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/cbook.py 2010-10-03 21:24:46 UTC (rev 8726)
+++ trunk/matplotlib/lib/matplotlib/cbook.py 2010-10-04 18:46:18 UTC (rev 8727)
@@ -1210,6 +1210,12 @@
'reverse the dictionary -- may lose data if values are not unique!'
return dict([(v,k) for k,v in d.items()])
+def restrict_dict(d, keys):
+ """
+ Return a dictionary that contains those keys that appear in both
+ d and keys, with values from d.
+ """
+ return dict([(k,v) for (k,v) in d.iteritems() if k in keys])
def report_memory(i=0): # argument may go away
'return the memory consumed by process'
Modified: trunk/matplotlib/lib/matplotlib/tests/test_cbook.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/tests/test_cbook.py 2010-10-03 21:24:46 UTC (rev 8726)
+++ trunk/matplotlib/lib/matplotlib/tests/test_cbook.py 2010-10-04 18:46:18 UTC (rev 8727)
@@ -12,3 +12,18 @@
assert cbook.is_string_like( "hello world" )
assert_equal( cbook.is_string_like(10), False )
+
+def test_restrict_dict():
+ d = {'foo': 'bar', 1: 2}
+ d1 = cbook.restrict_dict(d, ['foo', 1])
+ assert_equal(d1, d)
+ d2 = cbook.restrict_dict(d, ['bar', 2])
+ assert_equal(d2, {})
+ d3 = cbook.restrict_dict(d, {'foo': 1})
+ assert_equal(d3, {'foo': 'bar'})
+ d4 = cbook.restrict_dict(d, {})
+ assert_equal(d4, {})
+ d5 = cbook.restrict_dict(d, set(['foo',2]))
+ assert_equal(d5, {'foo': 'bar'})
+ # check that d was not modified
+ assert_equal(d, {'foo': 'bar', 1: 2})
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|