diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 9d5f1ce..ce0bc3b 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -267,23 +267,25 @@ impl Args { )?; if !self.benchmark { - let outp = image.save_avif(self.output_file, self.name_type, self.keep)?; - console.notify_image( - &format!( - "Finished in {:.2?} \n {} → {}", - start.elapsed(), - ByteSize::b(image.metadata.size).to_string_as(true), - ByteSize::b(fsz).to_string_as(true) - ), - &outp, - )?; + image.save_avif(self.output_file, self.name_type, self.keep)?; } + console.notify_image( + &format!( + "Finished in {:.2?} \n {} → {}", + start.elapsed(), + ByteSize::b(image.metadata.size).to_string_as(true), + ByteSize::b(fsz).to_string_as(true) + ), + &image.bitmap, + )?; + console.finish_spinner(&format!( "Encoding finished in {:?} ({})", start.elapsed(), ByteSize::b(fsz).to_string_as(true).bold().green() )); + Ok(()) } } diff --git a/src/image_file.rs b/src/image_file.rs index d81a630..4a11429 100644 --- a/src/image_file.rs +++ b/src/image_file.rs @@ -115,7 +115,7 @@ impl ImageFile { Ok(self.encoded_data.len() as u64) } - pub fn save_avif(&self, path: Option, name: Name, keep: bool) -> Result { + pub fn save_avif(&self, path: Option, name: Name, keep: bool) -> Result<()> { let fname = name.generate_name(self); let binding = self.metadata.path.canonicalize()?; @@ -125,7 +125,7 @@ impl ImageFile { if let Some(new_path) = path { fs::write(new_path, &self.encoded_data)?; - return Ok(avif_name); + return Ok(()); } if !keep { @@ -138,12 +138,12 @@ impl ImageFile { fs::rename(&binding, &avif_name)?; - return Ok(avif_name); + return Ok(()); } fs::write(&avif_name, &self.encoded_data)?; - Ok(avif_name) + Ok(()) } pub fn original_name(&self) -> String { diff --git a/src/utils.rs b/src/utils.rs index 1e8023f..58b91a4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,8 +1,9 @@ use std::{fmt::Write, fs, path::Path, time::Duration}; use color_eyre::Result; +use image::DynamicImage; use indicatif::{ProgressBar, ProgressState, ProgressStyle}; -use notify_rust::Notification; +use notify_rust::{Image, Notification}; use once_cell::sync::Lazy; use spinoff::{spinners, Color, Spinner, Streams}; @@ -78,13 +79,19 @@ impl ConsoleMsg { Ok(()) } - pub fn notify_image(&self, message: &str, image_path: &Path) -> Result<()> { + pub fn notify_image(&self, message: &str, image: &DynamicImage) -> Result<()> { + let img = image.resize(512, 512, image::imageops::FilterType::Nearest); + if self.notify { Notification::new() .appname("AVIF Converter") .summary("Conversion Completed") .body(message) - .image_path(image_path.as_os_str().to_str().unwrap()) + .image_data(Image::from_rgba( + img.width() as i32, + img.height() as i32, + img.to_rgba8().into_vec(), + )?) .show()?; }