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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
use std::fmt::Display;
/// A qualifier that determines which part of an asset to focus on, and thus which part of the asset to keep, when any
/// part of the asset is cropped. For overlays, this setting determines where to place the overlay.
#[derive(Debug, Clone)]
pub enum Gravity {
/// The compass direction represents a location in the asset, such as the top-right corner.
NorthEast,
/// The compass direction represents a location in the asset, such as the top-center.
North,
/// The compass direction represents a location in the asset, such as the top-left corner.
NorthWest,
/// The compass direction represents a location in the asset, such as the right-center.
West,
/// The compass direction represents a location in the asset, such as the bottom-left corner.
SouthWest,
/// The compass direction represents a location in the asset, such as the bottom-center.
South,
/// The compass direction represents a location in the asset, such as the bottom-right corner.
SouthEast,
/// The compass direction represents a location in the asset, such as the left-center.
East,
/// The compass direction represents the center of the asset.
Center,
/// Automatically detect all eyes in an image with the Advanced Facial Attribute Detection add-on and make them
/// the focus of the transformation.
AdvEyes,
/// Automatically detect the largest face in an image with the Advanced Facial Attribute Detection add-on and make
/// it the focus of the transformation.
AdvFace,
/// Automatically detect all faces in an image with the Advanced Facial Attribute Detection add-on and make them
/// the focus of the transformation.
AdvFaces,
/// Use custom coordinates that were previously specified (e.g., as part of the image upload method) and make them
/// the focus of the transformation. Defaults to center gravity if no custom coordinates have been specified.
Custom,
/// Same as Custom gravity, but defaults to face gravity if no custom coordinates have been specified.
CustomFace,
/// Same as Custom gravity, but defaults to AdvFace gravity if no custom coordinates have been specified.
CustomAdvFace,
/// Same as Custom gravity, but defaults to AdvFaces gravity if no custom coordinates have been specified.
CustomAdvFaces,
/// Same as Custom gravity, but defaults to Faces gravity if no custom coordinates have been specified.
CustomFaces,
/// Automatically detect the largest face in an image and make it the focus of the transformation. Any previously
/// specified face coordinates (during upload, with the Admin API, or via the Cloudinary Console) override the
/// automatically detected faces and are used instead. Defaults to North gravity if no face is detected or
/// previously specified. You can also use AutoFace or FaceCenter so that the gravity will default to auto or
/// center if no face is detected or specified.
Face,
/// Same as Face gravity, but defaults to Center gravity if no face is detected.
FaceCenter,
/// Same as Face gravity, but defaults to Auto gravity if no face is detected.
FaceAuto,
/// Same as Face gravity, but detects all the faces in an image and uses the rectangle containing all face
/// coordinates as the basis of the transformation. Any previously specified face coordinates (during upload, with
/// the Admin API, or via the Cloudinary Console) override the automatically detected faces and are used instead.
/// Defaults to North gravity if no faces are detected or previously specified. You can also use AutoFaces or
/// FacesCenter so that the gravity will default to auto or center if no faces are detected or specified.
Faces,
/// Same as Faces gravity, but defaults to Center gravity if no face is detected.
FacesCenter,
/// Same as Faces gravity, but defaults to Auto gravity if no face is detected.
FacesAuto,
/// Detect all text elements in an image using the OCR Text Detection and Extraction add-on and use the detected
/// bounding box coordinates as the basis of the transformation.
OcrText,
/// Applies deep-learning algorithms to identify the subjects of an image that are most likely to attract a
/// person's gaze.
AutoSubject,
/// Uses a combination of saliency heuristics to automatically detect significant regions in the image.
AutoClassic,
}
impl Display for Gravity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Gravity::NorthEast => write!(f, "g_north_east"),
Gravity::North => write!(f, "g_north"),
Gravity::NorthWest => write!(f, "g_north_west"),
Gravity::West => write!(f, "g_west"),
Gravity::SouthWest => write!(f, "g_south_west"),
Gravity::South => write!(f, "g_south"),
Gravity::SouthEast => write!(f, "g_south_east"),
Gravity::East => write!(f, "g_east"),
Gravity::Center => write!(f, "g_center"),
Gravity::AdvEyes => write!(f, "g_adv_eyes"),
Gravity::AdvFace => write!(f, "g_adv_face"),
Gravity::AdvFaces => write!(f, "g_adv_faces"),
Gravity::Custom => write!(f, "g_custom"),
Gravity::CustomFace => write!(f, "g_custom:face"),
Gravity::CustomAdvFace => write!(f, "g_custom:adv_face"),
Gravity::CustomAdvFaces => write!(f, "g_custom:adv_faces"),
Gravity::CustomFaces => write!(f, "g_custom:faces"),
Gravity::Face => write!(f, "g_face"),
Gravity::FaceCenter => write!(f, "g_face:center"),
Gravity::FaceAuto => write!(f, "g_face:auto"),
Gravity::Faces => write!(f, "g_faces"),
Gravity::FacesCenter => write!(f, "g_faces:center"),
Gravity::FacesAuto => write!(f, "g_faces:auto"),
Gravity::OcrText => write!(f, "g_ocr_text"),
Gravity::AutoSubject => write!(f, "g_auto:subject"),
Gravity::AutoClassic => write!(f, "g_auto:classic"),
}
}
}
#[cfg(test)]
mod tests {
use crate::transformation::gravity::Gravity;
#[test]
fn test_gravity_to_string() {
assert_eq!(Gravity::NorthEast.to_string(), "g_north_east");
assert_eq!(Gravity::North.to_string(), "g_north");
assert_eq!(Gravity::NorthWest.to_string(), "g_north_west");
assert_eq!(Gravity::West.to_string(), "g_west");
assert_eq!(Gravity::SouthWest.to_string(), "g_south_west");
assert_eq!(Gravity::South.to_string(), "g_south");
assert_eq!(Gravity::SouthEast.to_string(), "g_south_east");
assert_eq!(Gravity::East.to_string(), "g_east");
assert_eq!(Gravity::Center.to_string(), "g_center");
assert_eq!(Gravity::AdvEyes.to_string(), "g_adv_eyes");
assert_eq!(Gravity::AdvFace.to_string(), "g_adv_face");
assert_eq!(Gravity::AdvFaces.to_string(), "g_adv_faces");
assert_eq!(Gravity::Custom.to_string(), "g_custom");
assert_eq!(Gravity::CustomFace.to_string(), "g_custom:face");
assert_eq!(Gravity::CustomAdvFace.to_string(), "g_custom:adv_face");
assert_eq!(Gravity::CustomAdvFaces.to_string(), "g_custom:adv_faces");
assert_eq!(Gravity::CustomFaces.to_string(), "g_custom:faces");
assert_eq!(Gravity::Face.to_string(), "g_face");
assert_eq!(Gravity::FaceCenter.to_string(), "g_face:center");
assert_eq!(Gravity::FaceAuto.to_string(), "g_face:auto");
assert_eq!(Gravity::Faces.to_string(), "g_faces");
assert_eq!(Gravity::FacesCenter.to_string(), "g_faces:center");
assert_eq!(Gravity::FacesAuto.to_string(), "g_faces:auto");
assert_eq!(Gravity::OcrText.to_string(), "g_ocr_text");
assert_eq!(Gravity::AutoSubject.to_string(), "g_auto:subject");
assert_eq!(Gravity::AutoClassic.to_string(), "g_auto:classic");
}
}