Skip to content

Commit 6cb1c87

Browse files
authored
Merge pull request #103 from lguerard/save_as_suffix
Add the option to add a suffix to the newly created file name
2 parents 9574ebf + d85ccd9 commit 6cb1c87

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/imcflibs/imagej/misc.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ def write_ordereddict_to_csv(out_file, content):
523523
dict_writer.writerows(content)
524524

525525

526-
def save_image_in_format(imp, format, out_dir, series, pad_number, split_channels):
526+
def save_image_in_format(imp, format, out_dir, series, pad_number, split_channels, suffix=""):
527527
"""Save an ImagePlus object in the specified format.
528528
529529
This function provides flexible options for saving ImageJ images in various
@@ -552,6 +552,8 @@ def save_image_in_format(imp, format, out_dir, series, pad_number, split_channel
552552
If True, split channels and save them individually in separate folders
553553
named "C1", "C2", etc. inside out_dir. If False, save all channels in a
554554
single file.
555+
suffix : str, optional
556+
Text to be added to the filename, by default an empty string.
555557
556558
Notes
557559
-----
@@ -616,20 +618,20 @@ def save_image_in_format(imp, format, out_dir, series, pad_number, split_channel
616618

617619
out_path = pathtools.join2(
618620
dir_to_save[index],
619-
basename + "_series_" + str(series).zfill(pad_number),
621+
basename + "_series_" + str(series).zfill(pad_number) + suffix,
620622
)
621623

622624
if format == "ImageJ-TIF":
623625
pathtools.create_directory(dir_to_save[index])
624-
IJ.saveAs(current_imp, "Tiff", out_path + ".tif")
626+
IJ.saveAs(current_imp, "Tiff", out_path + suffix + ".tif")
625627

626628
elif format == "BMP":
627629
out_folder = os.path.join(out_dir, basename + os.path.sep)
628630
pathtools.create_directory(out_folder)
629631
StackWriter.save(current_imp, out_folder, "format=bmp")
630632

631633
else:
632-
bf.export(current_imp, out_path + out_ext[format])
634+
bf.export(current_imp, out_path + suffix + out_ext[format])
633635

634636
current_imp.close()
635637

0 commit comments

Comments
 (0)