Newer
Older
#[derive(Copy, Clone, Serialize, Deserialize, ValueEnum, Debug)]
pub enum FlipDirection {
#[serde(rename = "vertical")]
Vertical,
#[serde(rename = "horizontal")]
Horizontal,
#[serde(rename = "both")]
Both,
}
#[derive(Debug, Clone, Parser, Serialize, Deserialize)]
#[clap(author, version = "0.3.0")]
pub struct Flip {
#[serde(default)]
pub output: String,
/// The axis along which the image should be flipped
#[clap(short, long, value_enum)]
direction: FlipDirection,
}
impl Flip {
pub fn run<T: GenericImage>(&self, image: &T) -> anyhow::Result<TypedOutputFormat<T>>
where
T::Pixel: 'static,
<T::Pixel as Pixel>::Subpixel: 'static,
{
use FlipDirection::*;
match self.direction {
Vertical => Ok(imageops::flip_vertical(image)),
Horizontal => Ok(imageops::flip_horizontal(image)),
Both => {
let mut image = imageops::flip_horizontal(image);
imageops::flip_vertical_in_place(&mut image);
Ok(image)
}