Newer
Older
#[inline(always)]
fn one() -> f32 {
1.0
}
#[derive(Debug, Clone, Parser, Serialize, Deserialize)]
#[clap(author, version = "0.3.0")]
pub struct Scale {
#[serde(default)]
pub output: String,
/// The scale factor to use; numbers between 0-1 shrink the image; numbers > 1 enlarge
#[clap(short, long, default_value_t = 1.0)]
#[serde(default = "one")]
factor: f32,
}
impl Scale {
pub fn run<T: GenericImage>(&self, image: &T) -> anyhow::Result<TypedOutputFormat<T>>
where
T::Pixel: 'static,
<T::Pixel as Pixel>::Subpixel: 'static,
{
let width = (image.width() as f32 * self.factor) as u32;
let height = (image.height() as f32 * self.factor) as u32;
Ok(imageops::resize(image, width, height, FilterType::Nearest))
}