From 5247dd593c1dbbbd94eb4d7bfe33c293a9cf7dbd Mon Sep 17 00:00:00 2001 From: Ren Kararou Date: Mon, 13 Nov 2023 14:13:37 -0600 Subject: [PATCH] png write functionality --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/main.rs | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8a5976c..f85115c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -475,7 +475,7 @@ dependencies = [ [[package]] name = "rndfile" -version = "0.1.0" +version = "0.1.1" dependencies = [ "clap", "image", diff --git a/Cargo.toml b/Cargo.toml index 0a433ad..91df5f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rndfile" -version = "0.1.0" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/main.rs b/src/main.rs index 7a8183f..46bc9b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use clap::Parser; #[cfg(feature = "image")] -use image::GenericImageView; +use image::{GenericImageView, ImageFormat}; use rand::seq::SliceRandom; use walkdir::WalkDir; @@ -23,6 +23,9 @@ struct Args { #[arg(long, short)] out: Option, // Output file #[cfg(feature = "image")] + #[arg(long, short)] + png: Option, + #[cfg(feature = "image")] #[arg(long)] width: Option, #[cfg(feature = "image")] @@ -137,8 +140,14 @@ fn main() -> Result<(), Error> { f.flush() .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(()) }