1
|
|
|
<?php namespace Nord\Lumen\ImageManager\Adapters\Cloudinary; |
2
|
|
|
|
3
|
|
|
class CloudinaryImageTransformation |
4
|
|
|
{ |
5
|
|
|
const CROP_SCALE = 'scale'; |
6
|
|
|
const CROP_FILL = 'fill'; |
7
|
|
|
const CROP_LFILL = 'fill'; |
8
|
|
|
const CROP_FIT = 'fit'; |
9
|
|
|
const CROP_MFIT = 'mfit'; |
10
|
|
|
const CROP_LIMIT = 'limit'; |
11
|
|
|
const CROP_PAD = 'pad'; |
12
|
|
|
const CROP_MPAD = 'mpad'; |
13
|
|
|
const CROP_CROP = 'crop'; |
14
|
|
|
const CROP_THUMB = 'thumb'; |
15
|
|
|
const GRAVITY_NW = 'north_west'; |
16
|
|
|
const GRAVITY_N = 'north'; |
17
|
|
|
const GRAVITY_NE = 'north_east'; |
18
|
|
|
const GRAVITY_W = 'west'; |
19
|
|
|
const GRAVITY_CENTER = 'center'; |
20
|
|
|
const GRAVITY_E = 'east'; |
21
|
|
|
const GRAVITY_SW = 'south_west'; |
22
|
|
|
const GRAVITY_S = 'south'; |
23
|
|
|
const GRAVITY_SE = 'south_east'; |
24
|
|
|
const GRAVITY_XY = 'xy_center'; |
25
|
|
|
const GRAVITY_FACE = 'face'; |
26
|
|
|
const GRAVITY_FACES = 'faces'; |
27
|
|
|
const GRAVITY_FACE_CENTER = 'face:center'; |
28
|
|
|
const GRAVITY_FACES_CENTER = 'faces:center'; |
29
|
|
|
const GRAVITY_CUSTOM = 'custom'; |
30
|
|
|
const RADIUS_MAX = 'max'; |
31
|
|
|
const ANGLE_AUTO_RIGHT = 'auto_right'; |
32
|
|
|
const ANGLE_AUTO_LEFT = 'auto_left'; |
33
|
|
|
const ANGLE_EXIF = 'exif'; |
34
|
|
|
const ANGLE_VFLIP = 'vflip'; |
35
|
|
|
const ANGLE_HFLIP = 'hflip'; |
36
|
|
|
const EFFECT_GRAYSCALE = 'grayscale'; |
37
|
|
|
const EFFECT_BLACKWHITE = 'blackwhite'; |
38
|
|
|
const EFFECT_OIL_PAINT = 'oil_paint'; |
39
|
|
|
const EFFECT_NEGATE = 'negate'; |
40
|
|
|
const EFFECT_VIGETTE = 'vigette'; |
41
|
|
|
const EFFECT_SEPIA = 'sepia'; |
42
|
|
|
const EFFECT_BRIGHTNESS = 'brightness'; |
43
|
|
|
const EFFECT_AUTO_BRIGHTNESS = 'auto_brightness'; |
44
|
|
|
const EFFECT_FILL_LIGHT = 'fill_light'; |
45
|
|
|
const EFFECT_SATURATION = 'saturation'; |
46
|
|
|
const EFFECT_HUE = 'hue'; |
47
|
|
|
const EFFECT_PIXELATE = 'pixelate'; |
48
|
|
|
const EFFECT_PIXELATE_REGION = 'pixelate_region'; |
49
|
|
|
const EFFECT_PIXELATE_FACES = 'pixelate_faces'; |
50
|
|
|
const EFFECT_GRADIENT_FADE = 'gradient_fade'; |
51
|
|
|
const EFFECT_BLUR = 'blur'; |
52
|
|
|
const EFFECT_BLUR_REGION = 'blur_region'; |
53
|
|
|
const EFFECT_BLUR_FACES = 'blur_faces'; |
54
|
|
|
const EFFECT_SHARPEN = 'sharpen'; |
55
|
|
|
const EFFECT_UNSHARP_MASK = 'unsharp_mask'; |
56
|
|
|
const EFFECT_CONTRAST = 'constrast'; |
57
|
|
|
const EFFECT_AUTO_CONTRAST = 'auto_constrast'; |
58
|
|
|
const EFFECT_VIBRANCE = 'vibrance'; |
59
|
|
|
const EFFECT_RED = 'red'; |
60
|
|
|
const EFFECT_GREEN = 'green'; |
61
|
|
|
const EFFECT_BLUE = 'blue'; |
62
|
|
|
const EFFECT_AUTO_COLOR = 'auto_color'; |
63
|
|
|
const EFFECT_IMPROVE = 'improve'; |
64
|
|
|
const EFFECT_SCREEN = 'screen'; |
65
|
|
|
const EFFECT_MULTIPLY = 'multiply'; |
66
|
|
|
const EFFECT_MAKE_TRANSPARENT = 'make_transparent'; |
67
|
|
|
const EFFECT_TRIM = 'trim'; |
68
|
|
|
const EFFECT_SHADOW = 'shadow'; |
69
|
|
|
const FLAG_KEEP_IPTC = 'keep_iptc'; |
70
|
|
|
const FLAG_ATTACHMENT = 'attachment'; |
71
|
|
|
const FLAG_RELATIVE = 'relative'; |
72
|
|
|
const FLAG_REGION_RELATIVE = 'region_relative'; |
73
|
|
|
const FLAG_PROGRESSIVE = 'progressive'; |
74
|
|
|
const FLAG_PNG8 = 'png8'; |
75
|
|
|
const FLAG_FORCE_STRIP = 'force_strip'; |
76
|
|
|
const FLAG_CUTTER = 'cutter'; |
77
|
|
|
const FLAG_CLIP = 'clip'; |
78
|
|
|
const FLAG_AWEBP = 'awebp'; |
79
|
|
|
const FLAG_LAYER_APPLY = 'layer_apply'; |
80
|
|
|
const FLAG_IGNORE_ASPECT_RATIO = 'ignore_aspect_ratio'; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var string |
84
|
|
|
*/ |
85
|
|
|
public $crop; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @var integer|float |
89
|
|
|
*/ |
90
|
|
|
public $width; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @var integer|float |
94
|
|
|
*/ |
95
|
|
|
public $height; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @var string |
99
|
|
|
*/ |
100
|
|
|
public $gravity; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @var integer |
104
|
|
|
*/ |
105
|
|
|
public $x; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @var integer |
109
|
|
|
*/ |
110
|
|
|
public $y; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @var integer |
114
|
|
|
*/ |
115
|
|
|
public $quality; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @var integer|string |
119
|
|
|
*/ |
120
|
|
|
public $radius; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @var integer|string |
124
|
|
|
*/ |
125
|
|
|
public $angle; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @var string |
129
|
|
|
*/ |
130
|
|
|
public $effect; |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @var integer |
134
|
|
|
*/ |
135
|
|
|
public $opacity; |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @var string |
139
|
|
|
*/ |
140
|
|
|
public $border; |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @var string |
144
|
|
|
*/ |
145
|
|
|
public $background; |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @var string |
149
|
|
|
*/ |
150
|
|
|
public $overlay; |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @var string |
154
|
|
|
*/ |
155
|
|
|
public $underlay; |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @var string |
159
|
|
|
*/ |
160
|
|
|
public $defaultImage; |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @var integer |
164
|
|
|
*/ |
165
|
|
|
public $page; |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @var integer |
169
|
|
|
*/ |
170
|
|
|
public $density; |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @var string |
174
|
|
|
*/ |
175
|
|
|
public $format; |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @var array |
179
|
|
|
*/ |
180
|
|
|
public $flags; |
181
|
|
|
|
182
|
|
|
/** |
183
|
|
|
* @var string |
184
|
|
|
*/ |
185
|
|
|
public $transformation; |
186
|
|
|
|
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* CloudinaryImageTransformation constructor. |
190
|
|
|
* |
191
|
|
|
* @param array $properties |
192
|
|
|
*/ |
193
|
|
View Code Duplication |
public function __construct(array $properties) |
|
|
|
|
194
|
|
|
{ |
195
|
|
|
foreach ($properties as $property => $value) { |
196
|
|
|
$setter = 'set' . ucfirst($properties); |
197
|
|
|
if (method_exists($this, $setter)) { |
198
|
|
|
$this->$property = $this->$setter($value); |
199
|
|
|
} else { |
200
|
|
|
$this->$property = $value; |
201
|
|
|
} |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return array |
208
|
|
|
*/ |
209
|
|
|
public function getFlags() |
210
|
|
|
{ |
211
|
|
|
return implode('.', $this->flags); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @return array |
217
|
|
|
*/ |
218
|
|
View Code Duplication |
public function toArray() |
|
|
|
|
219
|
|
|
{ |
220
|
|
|
$array = []; |
221
|
|
|
|
222
|
|
|
foreach (array_keys(get_object_vars($this)) as $property) { |
223
|
|
|
$getter = 'get' . ucfirst($property); |
224
|
|
|
if (method_exists($this, $getter)) { |
225
|
|
|
$array[snake_case($property)] = $this->$getter(); |
226
|
|
|
} else { |
227
|
|
|
$array[snake_case($property)] = $this->$property; |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
return $array; |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.