1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
use std::fmt::{Display, Formatter};
use super::aspect_ratio::AspectRatio;
#[derive(Debug, Clone)]
pub enum ResizeMode {
/// Resizes the image to the specified width and aspect ratio.
ScaleByWidth {
width: u32,
/// Aspect ratio - if not specified the original aspect ratio is preserved
ar: Option<AspectRatio>,
/// liquid - enables content-aware liquid rescaling (also sometimes known as 'seam carving'), which can be
/// useful when changing the aspect ratio of an image.
liquid: Option<()>,
},
/// Resizes the image to the specified height and aspect ratio.
ScaleByHeight {
height: u32,
/// Aspect ratio - if not specified the original aspect ratio is preserved
ar: Option<AspectRatio>,
/// g_liquid - enables content-aware liquid rescaling (also sometimes known as 'seam carving'), which can be
/// useful when changing the aspect ratio of an image.
liquid: Option<()>,
},
/// Resizes the image to the specified dimensions without retaining the original aspect ratio.
Scale {
width: u32,
height: u32,
/// liquid - enables content-aware liquid rescaling (also sometimes known as 'seam carving'), which can be useful
/// when changing the aspect ratio of an image.
liquid: Option<()>,
},
}
impl Display for ResizeMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ResizeMode::ScaleByWidth { ar, width, liquid } => write!(
f,
"{}c_scale,w_{}{}",
ar.as_ref()
.map(|ar| format!("{},", ar))
.unwrap_or("".into()),
width,
liquid.map(|_| ",g_liquid").unwrap_or("")
),
ResizeMode::ScaleByHeight { height, ar, liquid } => write!(
f,
"{}c_scale,h_{}{}",
ar.as_ref()
.map(|ar| format!("{},", ar))
.unwrap_or("".into()),
height,
liquid.map(|_| ",g_liquid").unwrap_or("")
),
ResizeMode::Scale {
width,
height,
liquid,
} => write!(
f,
"c_scale,w_{},h_{}{}",
width,
height,
liquid.map(|_| ",g_liquid").unwrap_or("")
),
}
}
}