Assume stdin format is png

This commit is contained in:
2025-07-14 18:41:59 +02:00
parent 3222f1b8be
commit 509be59572

View File

@ -1,7 +1,7 @@
use clap::Parser; use clap::Parser;
use eyre::{Context, ContextCompat, bail, ensure, eyre}; use eyre::{Context, ContextCompat, bail, ensure, eyre};
use image::{ use image::{
DynamicImage, GrayAlphaImage, ImageReader, DynamicImage, GrayAlphaImage, ImageFormat, ImageReader,
imageops::{flip_vertical_in_place, overlay}, imageops::{flip_vertical_in_place, overlay},
}; };
use nix::ioctl_write_ptr; use nix::ioctl_write_ptr;
@ -15,6 +15,8 @@ use std::{
#[derive(Parser)] #[derive(Parser)]
struct Opt { struct Opt {
/// Path to the image-blob. "-" means stdin. /// Path to the image-blob. "-" means stdin.
///
/// When reading from stdin, format must be PNG.
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>"
@ -70,7 +72,9 @@ fn load_wallpaper(path: &Path) -> eyre::Result<GrayAlphaImage> {
eprintln!("Reading image from stdin"); eprintln!("Reading image from stdin");
let mut buf = vec![]; let mut buf = vec![];
stdin().read_to_end(&mut buf)?; stdin().read_to_end(&mut buf)?;
ImageReader::new(Cursor::new(buf)).decode()? let mut reader = ImageReader::new(Cursor::new(buf));
reader.set_format(ImageFormat::Png);
reader.decode()?
} else { } else {
eprintln!("Opening image at {path:?}"); eprintln!("Opening image at {path:?}");
ImageReader::open(path)?.decode()? ImageReader::open(path)?.decode()?