mod config; mod effects; use anyhow::{Context, Result}; use std::io::Write as _; use std::process::{Command, Stdio}; fn main() -> Result<()> { let paths: Vec = std::env::args().skip(1).collect(); if paths.is_empty() { eprintln!("Usage: rs-pictures [image2 ...]"); eprintln!("No image paths provided."); std::process::exit(1); } let config = config::Config::load().context("Failed to load config")?; for path in &paths { if let Err(e) = process_image(path, &config) { eprintln!("Error processing '{}': {e:#}", path); } } Ok(()) } fn process_image(path: &str, config: &config::Config) -> Result<()> { let img = image::open(path) .with_context(|| format!("Failed to open image '{path}'"))? .into_rgba8(); let processed = effects::apply_effects(img, &config.effects); let mut png_bytes: Vec = Vec::new(); image::DynamicImage::ImageRgba8(processed) .write_to( &mut std::io::Cursor::new(&mut png_bytes), image::ImageFormat::Png, ) .context("Failed to encode processed image as PNG")?; let mut child = Command::new("swappy") .args(["-f", "-"]) .stdin(Stdio::piped()) .spawn() .context("Failed to spawn swappy. Is it installed and in PATH?")?; child .stdin .take() .context("Failed to get swappy stdin")? .write_all(&png_bytes) .context("Failed to write image data to swappy")?; let status = child.wait().context("Failed to wait for swappy")?; if !status.success() { eprintln!( "swappy exited with non-zero status for '{}': {}", path, status ); } Ok(()) }