Skip to content

Commit b0b7ab8

Browse files
committed
ENH: Allow nibabel.save() to accept kwargs to pass to img.to_filename()
1 parent 6a761fc commit b0b7ab8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

nibabel/loadsave.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def guessed_image_type(filename):
130130
raise ImageFileError(f'Cannot work out file type of "{filename}"')
131131

132132

133-
def save(img, filename):
133+
def save(img, filename, **kwargs):
134134
""" Save an image to file adapting format to `filename`
135135
136136
Parameters
@@ -139,6 +139,8 @@ def save(img, filename):
139139
image to save
140140
filename : str or os.PathLike
141141
filename (often implying filenames) to which to save `img`.
142+
\*\*kwargs : keyword arguments
143+
Keyword arguments to format-specific save
142144
143145
Returns
144146
-------
@@ -148,7 +150,7 @@ def save(img, filename):
148150

149151
# Save the type as expected
150152
try:
151-
img.to_filename(filename)
153+
img.to_filename(filename, **kwargs)
152154
except ImageFileError:
153155
pass
154156
else:
@@ -196,7 +198,7 @@ def save(img, filename):
196198
# Here, we either have a klass or a converted image.
197199
if converted is None:
198200
converted = klass.from_image(img)
199-
converted.to_filename(filename)
201+
converted.to_filename(filename, **kwargs)
200202

201203

202204
@deprecate_with_version('read_img_data deprecated. '

0 commit comments

Comments
 (0)