png write functionality
This commit is contained in:
parent
9a9ad14e07
commit
5247dd593c
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -475,7 +475,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rndfile"
|
name = "rndfile"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"image",
|
"image",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "rndfile"
|
name = "rndfile"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
use image::GenericImageView;
|
use image::{GenericImageView, ImageFormat};
|
||||||
use rand::seq::SliceRandom;
|
use rand::seq::SliceRandom;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
|
@ -23,6 +23,9 @@ struct Args {
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
out: Option<String>, // Output file
|
out: Option<String>, // Output file
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
|
#[arg(long, short)]
|
||||||
|
png: Option<String>,
|
||||||
|
#[cfg(feature = "image")]
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
width: Option<u32>,
|
width: Option<u32>,
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
|
@ -137,8 +140,14 @@ fn main() -> Result<(), Error> {
|
||||||
f.flush()
|
f.flush()
|
||||||
.expect("unable to flush outfile (something has gone comically wrong)");
|
.expect("unable to flush outfile (something has gone comically wrong)");
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
println!("{}", pick.display());
|
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "image")]
|
||||||
|
if let Some(png) = args.png.to_owned() {
|
||||||
|
if let Ok(img) = image::open(&pick) {
|
||||||
|
img.save_with_format(&png, ImageFormat::Png)
|
||||||
|
.expect("unable to write png");
|
||||||
|
};
|
||||||
|
};
|
||||||
|
println!("{}", pick.display());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue