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 nix::ioctl_write_ptr;
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
|
io::{Cursor, Read, stdin},
|
||||||
os::fd::AsRawFd,
|
os::fd::AsRawFd,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
/// Path to the image-blob.
|
/// Path to the image-blob. "-" means stdin.
|
||||||
pub path: PathBuf,
|
pub path: PathBuf,
|
||||||
|
|
||||||
/// Stamp an image onto the final image. "<x>:<y>:<path>"
|
/// 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> {
|
fn load_wallpaper(path: &Path) -> eyre::Result<GrayAlphaImage> {
|
||||||
eprintln!("Opening image at {path:?}");
|
let mut image = if path == Path::new("-") {
|
||||||
|
eprintln!("Reading image from stdin");
|
||||||
let mut image = ImageReader::open(path)?.decode()?;
|
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);
|
let image_dimensions = (image.width() as usize, image.height() as usize);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user