Wire resize algorithm selection, overwrite behavior, and fix rotation/flip scope
This commit is contained in:
@@ -46,6 +46,22 @@ impl ResizeConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Resize Algorithm ---
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum ResizeAlgorithm {
|
||||
Lanczos3,
|
||||
CatmullRom,
|
||||
Bilinear,
|
||||
Nearest,
|
||||
}
|
||||
|
||||
impl Default for ResizeAlgorithm {
|
||||
fn default() -> Self {
|
||||
Self::Lanczos3
|
||||
}
|
||||
}
|
||||
|
||||
// --- Rotation / Flip ---
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
@@ -225,6 +241,21 @@ impl AdjustmentsConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// --- Overwrite Behavior ---
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub enum OverwriteBehavior {
|
||||
AutoRename,
|
||||
Overwrite,
|
||||
Skip,
|
||||
}
|
||||
|
||||
impl Default for OverwriteBehavior {
|
||||
fn default() -> Self {
|
||||
Self::AutoRename
|
||||
}
|
||||
}
|
||||
|
||||
// --- Rename ---
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
|
||||
@@ -3,11 +3,19 @@ use fast_image_resize::{images::Image, Resizer, ResizeOptions, ResizeAlg, Filter
|
||||
use crate::error::{PixstripError, Result};
|
||||
use crate::types::Dimensions;
|
||||
|
||||
use super::ResizeConfig;
|
||||
use super::{ResizeConfig, ResizeAlgorithm};
|
||||
|
||||
pub fn resize_image(
|
||||
src: &image::DynamicImage,
|
||||
config: &ResizeConfig,
|
||||
) -> Result<image::DynamicImage> {
|
||||
resize_image_with_algorithm(src, config, ResizeAlgorithm::default())
|
||||
}
|
||||
|
||||
pub fn resize_image_with_algorithm(
|
||||
src: &image::DynamicImage,
|
||||
config: &ResizeConfig,
|
||||
algorithm: ResizeAlgorithm,
|
||||
) -> Result<image::DynamicImage> {
|
||||
let original = Dimensions {
|
||||
width: src.width(),
|
||||
@@ -40,7 +48,13 @@ pub fn resize_image(
|
||||
);
|
||||
|
||||
let mut resizer = Resizer::new();
|
||||
let options = ResizeOptions::new().resize_alg(ResizeAlg::Convolution(FilterType::Lanczos3));
|
||||
let alg = match algorithm {
|
||||
ResizeAlgorithm::Lanczos3 => ResizeAlg::Convolution(FilterType::Lanczos3),
|
||||
ResizeAlgorithm::CatmullRom => ResizeAlg::Convolution(FilterType::CatmullRom),
|
||||
ResizeAlgorithm::Bilinear => ResizeAlg::Convolution(FilterType::Bilinear),
|
||||
ResizeAlgorithm::Nearest => ResizeAlg::Nearest,
|
||||
};
|
||||
let options = ResizeOptions::new().resize_alg(alg);
|
||||
|
||||
resizer
|
||||
.resize(&src_image, &mut dst_image, &options)
|
||||
|
||||
Reference in New Issue
Block a user