Revision: 6282
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6282&view=rev
Author:   jdh2358
Date:     2008-10-20 14:09:30 +0000 (Mon, 20 Oct 2008)

Log Message:
-----------
added image.thumbnail function

Modified Paths:
--------------
    trunk/matplotlib/CHANGELOG
    trunk/matplotlib/doc/_static/logo_sidebar_horiz.png
    trunk/matplotlib/examples/tests/backend_driver.py
    trunk/matplotlib/lib/matplotlib/axes.py
    trunk/matplotlib/lib/matplotlib/image.py
    trunk/matplotlib/matplotlibrc.template
    trunk/matplotlib/setupext.py

Modified: trunk/matplotlib/CHANGELOG
===================================================================
--- trunk/matplotlib/CHANGELOG  2008-10-20 09:04:54 UTC (rev 6281)
+++ trunk/matplotlib/CHANGELOG  2008-10-20 14:09:30 UTC (rev 6282)
@@ -1,3 +1,7 @@
+2008-10-20 Added image thumbnail generating function
+           matplotlib.image.thumbnail.  See
+           examples/misc/image_thumbnail.py - JDH
+
 2008-10-20 Applied scatleg patch based on ideas and work by Erik
            Tollerud and Jae-Joon Lee. - MM
 

Modified: trunk/matplotlib/doc/_static/logo_sidebar_horiz.png
===================================================================
(Binary files differ)

Modified: trunk/matplotlib/examples/tests/backend_driver.py
===================================================================
--- trunk/matplotlib/examples/tests/backend_driver.py   2008-10-20 09:04:54 UTC 
(rev 6281)
+++ trunk/matplotlib/examples/tests/backend_driver.py   2008-10-20 14:09:30 UTC 
(rev 6282)
@@ -28,7 +28,7 @@
     'alignment_test.py',
     'arctest.py',
     'arrow_demo.py',
-    'auto_layout.py',
+    #'auto_layout.py',
     'axes_demo.py',
     'axhspan_demo.py',
     'bar_stacked.py',

Modified: trunk/matplotlib/lib/matplotlib/axes.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/axes.py     2008-10-20 09:04:54 UTC (rev 
6281)
+++ trunk/matplotlib/lib/matplotlib/axes.py     2008-10-20 14:09:30 UTC (rev 
6282)
@@ -5453,11 +5453,13 @@
             If *None*, default to rc ``image.aspect`` value.
 
           *interpolation*:
-            Acceptable values are *None*, 'nearest', 'bilinear', 'bicubic',
-            'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser',
-            'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc',
-            'lanczos', 'blackman'
 
+            Acceptable values are *None*, 'nearest', 'bilinear',
+              'bicubic', 'spline16', 'spline36', 'hanning', 'hamming',
+              'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian',
+              'bessel', 'mitchell', 'sinc', 'lanczos',
+
+
             If *interpolation* is *None*, default to rc
             ``image.interpolation``. See also the *filternorm* and
             *filterrad* parameters

Modified: trunk/matplotlib/lib/matplotlib/image.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/image.py    2008-10-20 09:04:54 UTC (rev 
6281)
+++ trunk/matplotlib/lib/matplotlib/image.py    2008-10-20 14:09:30 UTC (rev 
6282)
@@ -319,10 +319,9 @@
         """
         Return the interpolation method the image uses when resizing.
 
-        One of
-
-        'bicubic', 'bilinear', 'blackman100', 'blackman256', 'blackman64',
-        'nearest', 'sinc144', 'sinc256', 'sinc64', 'spline16', 'spline36'
+        One of 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 
'hanning',
+        'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian',
+        'bessel', 'mitchell', 'sinc', 'lanczos',
         """
         return self._interpolation
 
@@ -330,9 +329,11 @@
         """
         Set the interpolation method the image uses when resizing.
 
-        ACCEPTS: ['bicubic' | 'bilinear' | 'blackman100' | 'blackman256' |
-        'blackman64', 'nearest' | 'sinc144' | 'sinc256' | 'sinc64' |
-        'spline16' | 'spline36']
+        ACCEPTS: ['nearest' | 'bilinear' | 'bicubic' | 'spline16' |
+          'spline36' | 'hanning' | 'hamming' | 'hermite' | 'kaiser' |
+          'quadric' | 'catrom' | 'gaussian' | 'bessel' | 'mitchell' |
+          'sinc' | 'lanczos' | ]
+
         """
         if s is None: s = rcParams['image.interpolation']
         s = s.lower()
@@ -764,3 +765,100 @@
     x = toarray(im)
     x.shape = im.size[1], im.size[0], 4
     return x
+
+def thumbnail(fname, scale=0.1, interpolation='bilinear', prefix='thumb_',
+              outdir=None, preview=False, extension='png'):
+    """
+    make a thumbnail of image in fname with output filename
+    [OUTDIR]/[PREFIX][BASENAME].EXTENSION where BASENAME is the
+    filename part of fname without the directory ar extension
+
+      *fname* the image file -- must be PNG or PIL readable if you
+         have `PIL <http://www.pythonware.com/products/pil/>`_ installed
+
+      *scale*
+        the scale factor for the thumbnail
+
+      *interpolation*
+        the interpolation scheme used in the resampling
+
+      *prefix*
+        the PREFIX of the output file name
+
+      *outdir*
+        the OUTDIR of the output filenamet - by default same as directory the 
source image lives in
+
+      *extension*
+        the EXTENSION for the output filename, one of 'png', 'pdf' or 'ps'
+
+      *preview*
+        if True, the default backend (presumably a user interface
+        backend) will be used which will cause a figure to be raised
+        if :func:`~matplotlib.pyplot.show` is called.  If it is False,
+        a pure image backend will be used depending on the extension,
+        'png'->FigureCanvasAgg, 'pdf'->FigureCanvasPDF,
+        'svg'->FigureCanvasSVG
+
+
+    See examples/misc/image_thumbnail.py.
+
+    .. htmlonly::
+
+        :ref:`misc-image_thumbnail`
+
+    Return value is the output filename of the thumbnail
+
+    """
+
+    basedir, basename = os.path.split(fname)
+    if outdir is None:
+        if not basedir:
+            basedir = os.curdir
+        outdir = basedir
+
+    if not os.path.exists(outdir) or not os.path.isdir(outdir):
+        raise IOError('output directory "%s" must be a directory'%outdir)
+
+    im = imread(fname)
+    rows, cols, depth = im.shape
+
+    # this doesn't really matter, it will cancel in the end, but we
+    # need it for the mpl API
+    dpi = 100
+
+
+    height = float(rows)/dpi*scale
+    width = float(cols)/dpi*scale
+
+    extension = extension.lower()
+
+    if preview:
+        # let the UI backend do everything
+        import matplotlib.pyplot as plt
+        fig = plt.figure(figsize=(width, height), dpi=dpi)
+    else:
+        if extension=='png':
+            from matplotlib.backends.backend_agg import FigureCanvasAgg as 
FigureCanvas
+            from matplotlib.figure import Figure
+        elif extension=='pdf':
+            from matplotlib.backends.backend_pdf import FigureCanvasPDF as 
FigureCanvas
+            from matplotlib.figure import Figure
+        elif extension=='svg':
+            from matplotlib.backends.backend_svg import FigureCanvasSVG as 
FigureCanvas
+            from matplotlib.figure import Figure
+        else:
+            raise ValueError("Can only handle extension 'png', 'svg' or 'pdf'")
+
+        fig = Figure(figsize=(width, height), dpi=dpi)
+        canvas = FigureCanvas(fig)
+
+
+
+
+    ax = fig.add_axes([0,0,1,1], aspect='auto', frameon=False, xticks=[], 
yticks=[])
+
+    basename, ext = os.path.splitext(basename)
+    ax.imshow(im, aspect='auto', resample=True, interpolation='bilinear')
+    outfile = os.path.join(outdir, '%s%s.%s'%(prefix, basename, extension))
+    fig.savefig(outfile, dpi=dpi)
+    return outfile

Modified: trunk/matplotlib/matplotlibrc.template
===================================================================
--- trunk/matplotlib/matplotlibrc.template      2008-10-20 09:04:54 UTC (rev 
6281)
+++ trunk/matplotlib/matplotlibrc.template      2008-10-20 14:09:30 UTC (rev 
6282)
@@ -265,8 +265,8 @@
 #image.cmap   : jet               # gray | jet etc...
 #image.lut    : 256               # the size of the colormap lookup table
 #image.origin : upper             # lower | upper
+#image.resample  : False
 
-
 ### CONTOUR PLOTS
 #contour.negative_linestyle :  dashed # dashed | solid
 

Modified: trunk/matplotlib/setupext.py
===================================================================
--- trunk/matplotlib/setupext.py        2008-10-20 09:04:54 UTC (rev 6281)
+++ trunk/matplotlib/setupext.py        2008-10-20 14:09:30 UTC (rev 6282)
@@ -942,6 +942,7 @@
     try:
         tcl_lib = tcl_vars.get("default", "TCL_LIB_SPEC")[1:-1].split()[0][2:]
         tcl_inc = tcl_vars.get("default", "TCL_INCLUDE_SPEC")[3:-1]
+
         tk_lib = tk_vars.get("default", "TK_LIB_SPEC")[1:-1].split()[0][2:]
         if tk_vars.has_option("default", "TK_INCLUDE_SPEC"):
             # On Ubuntu 8.04


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 the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to