parent
462e982784
commit
b6a238c67a
1 changed files with 12 additions and 3 deletions
15
src/main.rs
15
src/main.rs
|
|
@ -25,6 +25,7 @@ use oxipng::RowFilter;
|
||||||
use oxipng::StripChunks;
|
use oxipng::StripChunks;
|
||||||
use oxipng::{InFile, OutFile};
|
use oxipng::{InFile, OutFile};
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
use std::ffi::OsString;
|
||||||
use std::fs::DirBuilder;
|
use std::fs::DirBuilder;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
#[cfg(feature = "zopfli")]
|
#[cfg(feature = "zopfli")]
|
||||||
|
|
@ -64,7 +65,7 @@ fn main() {
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("recursive")
|
Arg::new("recursive")
|
||||||
.help("Recurse into subdirectories")
|
.help("Recurse into subdirectories and optimize all *.png/*.apng files")
|
||||||
.short('r')
|
.short('r')
|
||||||
.long("recursive")
|
.long("recursive")
|
||||||
.action(ArgAction::SetTrue),
|
.action(ArgAction::SetTrue),
|
||||||
|
|
@ -353,10 +354,10 @@ fn collect_files(
|
||||||
out_dir: &Option<PathBuf>,
|
out_dir: &Option<PathBuf>,
|
||||||
out_file: &OutFile,
|
out_file: &OutFile,
|
||||||
recursive: bool,
|
recursive: bool,
|
||||||
allow_stdin: bool,
|
top_level: bool, //explicitly specify files
|
||||||
) -> Vec<(InFile, OutFile)> {
|
) -> Vec<(InFile, OutFile)> {
|
||||||
let mut in_out_pairs = Vec::new();
|
let mut in_out_pairs = Vec::new();
|
||||||
let allow_stdin = allow_stdin && files.len() == 1;
|
let allow_stdin = top_level && files.len() == 1;
|
||||||
for input in files {
|
for input in files {
|
||||||
let using_stdin = allow_stdin && input.to_str().map_or(false, |p| p == "-");
|
let using_stdin = allow_stdin && input.to_str().map_or(false, |p| p == "-");
|
||||||
if !using_stdin && input.is_dir() {
|
if !using_stdin && input.is_dir() {
|
||||||
|
|
@ -389,6 +390,14 @@ fn collect_files(
|
||||||
let in_file = if using_stdin {
|
let in_file = if using_stdin {
|
||||||
InFile::StdIn
|
InFile::StdIn
|
||||||
} else {
|
} else {
|
||||||
|
// Skip non png files if not given on top level
|
||||||
|
if !top_level && {
|
||||||
|
let extension = input.extension().map(|f| f.to_ascii_lowercase());
|
||||||
|
extension != Some(OsString::from("png"))
|
||||||
|
&& extension != Some(OsString::from("apng"))
|
||||||
|
} {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
InFile::Path(input)
|
InFile::Path(input)
|
||||||
};
|
};
|
||||||
in_out_pairs.push((in_file, out_file));
|
in_out_pairs.push((in_file, out_file));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue