Add rotate flag

This commit is contained in:
Jan-Henrik 2021-08-26 15:01:37 +02:00
parent 175e6fa4fa
commit 2f379d2c81
2 changed files with 12 additions and 4 deletions

View file

@ -35,12 +35,16 @@ struct Feed {
#[derive(Clap)]
struct Print {
/// The image you want to print out
/// The path to the image you want to print out
input_image: String,
/// The ditherer supposed to be used. none is good for text and vector graphics
#[clap(arg_enum, short, long, default_value = "k-mean")]
ditherer: Ditherers,
/// Rotate picture by 90 degrees
#[clap(short, long)]
rotate: bool,
}
#[derive(ArgEnum)]
@ -87,7 +91,8 @@ async fn main_print(mut device: device::Device, print: Print) -> Result<(), Box<
10,
));
let image = image::Image::load(&std::path::PathBuf::from(print.input_image)).unwrap();
let image =
image::Image::load(&std::path::PathBuf::from(print.input_image), print.rotate).unwrap();
let image = match print.ditherer {
Ditherers::None => image,

View file

@ -22,9 +22,12 @@ fn rle_bytes(val: u8, mut counter: u32) -> Vec<u8> {
}
impl Image {
pub fn load(path: &Path) -> std::result::Result<Self, Box<dyn std::error::Error>> {
pub fn load(
path: &Path,
rotate: bool,
) -> std::result::Result<Self, Box<dyn std::error::Error>> {
let image = image::open(path)?;
let image = if rotate { image.rotate90() } else { image };
let image = image
.resize(
crate::protocol::PIXELS_PER_LINE as u32,