diff --git a/src/main.rs b/src/main.rs index 88249e2..7395a19 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,13 +7,14 @@ use image::{ use nix::ioctl_write_ptr; use std::{ fs::File, + io::{Cursor, Read, stdin}, os::fd::AsRawFd, path::{Path, PathBuf}, }; #[derive(Parser)] struct Opt { - /// Path to the image-blob. + /// Path to the image-blob. "-" means stdin. pub path: PathBuf, /// Stamp an image onto the final image. "::" @@ -65,9 +66,15 @@ fn to_grayscale(path: &Path, image: DynamicImage) -> GrayAlphaImage { } fn load_wallpaper(path: &Path) -> eyre::Result { - eprintln!("Opening image at {path:?}"); - - let mut image = ImageReader::open(path)?.decode()?; + let mut image = if path == Path::new("-") { + eprintln!("Reading image from stdin"); + let mut buf = vec![]; + stdin().read_to_end(&mut buf)?; + ImageReader::new(Cursor::new(buf)).decode()? + } else { + eprintln!("Opening image at {path:?}"); + ImageReader::open(path)?.decode()? + }; let image_dimensions = (image.width() as usize, image.height() as usize);