@@ -25,6 +25,7 @@ use oxipng::RowFilter;
25
25
use oxipng:: StripChunks ;
26
26
use oxipng:: { InFile , OutFile } ;
27
27
use rayon:: prelude:: * ;
28
+ use std:: ffi:: OsString ;
28
29
use std:: fs:: DirBuilder ;
29
30
use std:: io:: Write ;
30
31
#[ cfg( feature = "zopfli" ) ]
@@ -64,7 +65,7 @@ fn main() {
64
65
)
65
66
. arg (
66
67
Arg :: new ( "recursive" )
67
- . help ( "Recurse into subdirectories" )
68
+ . help ( "Recurse into subdirectories and optimize all *.png/*.apng files " )
68
69
. short ( 'r' )
69
70
. long ( "recursive" )
70
71
. action ( ArgAction :: SetTrue ) ,
@@ -353,10 +354,10 @@ fn collect_files(
353
354
out_dir : & Option < PathBuf > ,
354
355
out_file : & OutFile ,
355
356
recursive : bool ,
356
- allow_stdin : bool ,
357
+ top_level : bool , //explicitly specify files
357
358
) -> Vec < ( InFile , OutFile ) > {
358
359
let mut in_out_pairs = Vec :: new ( ) ;
359
- let allow_stdin = allow_stdin && files. len ( ) == 1 ;
360
+ let allow_stdin = top_level && files. len ( ) == 1 ;
360
361
for input in files {
361
362
let using_stdin = allow_stdin && input. to_str ( ) . map_or ( false , |p| p == "-" ) ;
362
363
if !using_stdin && input. is_dir ( ) {
@@ -389,6 +390,14 @@ fn collect_files(
389
390
let in_file = if using_stdin {
390
391
InFile :: StdIn
391
392
} else {
393
+ // Skip non png files if not given on top level
394
+ if !top_level && {
395
+ let extension = input. extension ( ) . map ( |f| f. to_ascii_lowercase ( ) ) ;
396
+ extension != Some ( OsString :: from ( "png" ) )
397
+ && extension != Some ( OsString :: from ( "apng" ) )
398
+ } {
399
+ continue ;
400
+ }
392
401
InFile :: Path ( input)
393
402
} ;
394
403
in_out_pairs. push ( ( in_file, out_file) ) ;
0 commit comments