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
70
71
72
73
74
75
76
77
78
use image::imageops::FilterType;
#[derive(Clone)]
pub struct Picture {
path: String,
crop: Option<(u32, u32, u32, u32)>,
resize: Option<(u32, u32, FilterType)>,
position: (u32, u32),
}
impl Picture {
pub fn new(path: &str) -> Picture {
let path = String::from(path);
Picture {
path,
resize: None,
crop: None,
position: (0, 0),
}
}
pub fn resize(&mut self, width: u32, height: u32, filter: FilterType) -> Self {
self.resize = Some((width, height, filter));
self.clone()
}
pub fn crop(&mut self, x: u32, y: u32, width: u32, height: u32) -> Self {
self.crop = Some((x, y, width, height));
self.clone()
}
pub fn position(&mut self, x: u32, y: u32) -> Self {
self.position = (x, y);
self.clone()
}
}
pub struct CropValues {
pub x: u32,
pub y: u32,
pub width: u32,
pub height: u32,
}
pub struct ResizeValues {
pub nwidth: u32,
pub nheight: u32,
pub filter: FilterType,
}
pub struct PictureValues<'a> {
pub path: &'a String,
pub x: i64,
pub y: i64,
pub crop: Option<CropValues>,
pub resize: Option<ResizeValues>,
}
pub fn extract(picture: &Picture) -> PictureValues {
PictureValues {
path: &picture.path,
x: picture.position.0 as i64,
y: picture.position.1 as i64,
crop: match picture.crop {
None => None,
Some(values) => Some(CropValues {
x: values.0,
y: values.1,
width: values.2,
height: values.3,
}),
},
resize: match picture.resize {
None => None,
Some(values) => Some(ResizeValues {
nwidth: values.0,
nheight: values.1,
filter: values.2,
}),
},
}
}