Skip to content

Commit a7cf13a

Browse files
authored
Merge pull request #167 from christianbrodbeck/save_image
[MRG] API: expose screenshot params in save_image()
2 parents cd2c11c + e5bcee4 commit a7cf13a

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Version 0.7
2424
to manually install ``ffmpeg``. ``imageio`` has been added as an optional
2525
dependency which can be installed with
2626
``$ pip install pysurfer[save_movie]``.
27+
- ``Brain.save_image`` now has the option to save with alpha channel and
28+
antialiasing.
2729

2830
Version 0.6
2931
-----------

surfer/tests/test_viz.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def test_image():
5757

5858
brain = Brain(*std_args, size=100)
5959
brain.save_image(tmp_name)
60+
brain.save_image(tmp_name, 'rgba', True)
6061
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='v')
6162
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='h')
6263
brain.save_montage(tmp_name, [['l', 'v'], ['m', 'f']])

surfer/viz.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ def save_single_image(self, filename, row=-1, col=-1):
20102010
mlab.draw(brain._f)
20112011
mlab.savefig(filename, figure=brain._f)
20122012

2013-
def save_image(self, filename):
2013+
def save_image(self, filename, mode='rgb', antialiased=False):
20142014
"""Save view from all panels to disk
20152015
20162016
Only mayavi image types are supported:
@@ -2020,15 +2020,23 @@ def save_image(self, filename):
20202020
----------
20212021
filename: string
20222022
path to new image file
2023+
mode: string
2024+
Either 'rgb' (default) to render solid background, or 'rgba' to
2025+
include alpha channel for transparent background
2026+
antialiased: bool
2027+
Antialias the image (see mlab.screenshot() for details; default
2028+
False)
20232029
2030+
Notes
2031+
-----
20242032
Due to limitations in TraitsUI, if multiple views or hemi='split'
20252033
is used, there is no guarantee painting of the windows will
20262034
complete before control is returned to the command line. Thus
20272035
we strongly recommend using only one figure window (which uses
20282036
a Mayavi figure to plot instead of TraitsUI) if you intend to
20292037
script plotting commands.
20302038
"""
2031-
misc.imsave(filename, self.screenshot())
2039+
misc.imsave(filename, self.screenshot(mode, antialiased))
20322040

20332041
def screenshot(self, mode='rgb', antialiased=False):
20342042
"""Generate a screenshot of current view
@@ -2040,11 +2048,8 @@ def screenshot(self, mode='rgb', antialiased=False):
20402048
mode: string
20412049
Either 'rgb' or 'rgba' for values to return
20422050
antialiased: bool
2043-
Antialias the image (see mlab.screenshot() for details)
2044-
row : int
2045-
row index of the brain to use
2046-
col : int
2047-
column index of the brain to use
2051+
Antialias the image (see mlab.screenshot() for details; default
2052+
False)
20482053
20492054
Returns
20502055
-------

0 commit comments

Comments
 (0)