Allow reading image from stdin
This commit is contained in:
15
src/main.rs
15
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. "<x>:<y>:<path>"
|
||||
@ -65,9 +66,15 @@ fn to_grayscale(path: &Path, image: DynamicImage) -> GrayAlphaImage {
|
||||
}
|
||||
|
||||
fn load_wallpaper(path: &Path) -> eyre::Result<GrayAlphaImage> {
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user