Revision: 3927
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=3927&view=rev
Author:   mdboom
Date:     2007-10-08 05:45:23 -0700 (Mon, 08 Oct 2007)

Log Message:
-----------
Save image resolution in the PNG file.

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/backends/backend_agg.py
    trunk/matplotlib/lib/matplotlib/backends/backend_gtkagg.py
    trunk/matplotlib/src/_backend_agg.cpp

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_agg.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_agg.py     2007-10-05 
22:11:32 UTC (rev 3926)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_agg.py     2007-10-08 
12:45:23 UTC (rev 3927)
@@ -415,5 +415,5 @@
         
     def print_png(self, filename, *args, **kwargs):
         self.draw()
-        self.get_renderer()._renderer.write_png(str(filename))
+        self.get_renderer()._renderer.write_png(str(filename), 
self.figure.dpi.get())
         

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_gtkagg.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_gtkagg.py  2007-10-05 
22:11:32 UTC (rev 3926)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_gtkagg.py  2007-10-08 
12:45:23 UTC (rev 3927)
@@ -97,6 +97,8 @@
                                    0, 0, 0, 0, w, h)
         if DEBUG: print 'FigureCanvasGTKAgg.done'
 
+    def print_png(self, filename, *args, **kwargs):
+        return FigureCanvasAgg.print_png(self, filename, *args, **kwargs)
 
 """\
 Traceback (most recent call last):

Modified: trunk/matplotlib/src/_backend_agg.cpp
===================================================================
--- trunk/matplotlib/src/_backend_agg.cpp       2007-10-05 22:11:32 UTC (rev 
3926)
+++ trunk/matplotlib/src/_backend_agg.cpp       2007-10-08 12:45:23 UTC (rev 
3927)
@@ -2283,7 +2283,7 @@
 {
   _VERBOSE("RendererAgg::write_png");
   
-  args.verify_length(1);
+  args.verify_length(1, 2);
   
   FILE *fp;
   Py::Object o = Py::Object(args[0]);
@@ -2344,6 +2344,13 @@
               width, height, 8,
               PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
               PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
+
+  // Save the dpi of the image in the file
+  if (args.size() == 2) {
+    double dpi = Py::Float(args[1]);
+    size_t dots_per_meter = (size_t)(dpi / (2.54 / 100.0));
+    png_set_pHYs(png_ptr, info_ptr, dots_per_meter, dots_per_meter, 
PNG_RESOLUTION_METER);
+  }
   
   // this a a color image!
   sig_bit.gray = 0;
@@ -2619,7 +2626,7 @@
   add_varargs_method("write_rgba", &RendererAgg::write_rgba,
                     "write_rgba(fname)");
   add_varargs_method("write_png", &RendererAgg::write_png,
-                    "write_png(fname)");
+                    "write_png(fname, dpi=None)");
   add_varargs_method("tostring_rgb", &RendererAgg::tostring_rgb,
                     "s = tostring_rgb()");
   add_varargs_method("tostring_argb", &RendererAgg::tostring_argb,


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to