Suffix option #77
This commit is contained in:
parent
74115e599f
commit
2264032e47
13
src/main.rs
13
src/main.rs
|
@ -44,6 +44,7 @@ fn main() {
|
|||
let keep_dates = opt.keep_dates;
|
||||
let png_optimization_level = opt.png_opt_level.clamp(0, 6);
|
||||
let lossless = opt.lossless;
|
||||
let suffix = opt.suffix;
|
||||
|
||||
let compress_by_size = opt.max_size.is_some();
|
||||
|
||||
|
@ -130,11 +131,21 @@ fn main() {
|
|||
result: false,
|
||||
};
|
||||
|
||||
let filename = if keep_structure {
|
||||
let mut filename = if keep_structure {
|
||||
input_file.strip_prefix(base_path.clone()).unwrap_or_else(|_| Path::new("")).as_os_str()
|
||||
} else {
|
||||
input_file.file_name().unwrap_or_default()
|
||||
};
|
||||
let mut basename = Path::new(filename).file_stem().unwrap_or_default().to_os_string();
|
||||
|
||||
if !suffix.is_empty() {
|
||||
basename.push(suffix.clone());
|
||||
if let Some(ext) = input_file.extension() {
|
||||
basename.push(".");
|
||||
basename.push(ext);
|
||||
}
|
||||
filename = basename.as_os_str();
|
||||
}
|
||||
|
||||
if filename.is_empty() {
|
||||
compression_result.error = "Cannot retrieve filename for {}. Skipping.".to_string();
|
||||
|
|
|
@ -102,6 +102,10 @@ pub struct Opt {
|
|||
#[structopt(long = "same-folder-as-input", conflicts_with = "output")]
|
||||
pub same_folder_as_input: bool,
|
||||
|
||||
/// convert the image to the selected format (jpg, png, webp, tiff)
|
||||
#[structopt(long = "suffix", default_value = "none")]
|
||||
pub suffix: String,
|
||||
|
||||
/// Files to process
|
||||
#[structopt(name = "FILE", parse(from_os_str))]
|
||||
pub files: Vec<PathBuf>,
|
||||
|
|
Loading…
Reference in New Issue