-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
239 lines (200 loc) · 7.35 KB
/
test.js
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
var assert = require('assert');
var aspect = require('./index');
describe('aspect.resize', function() {
var vertical = { x: 3456, y: 5184 };
var horizontal = { x: 5184, y: 3456 };
var maxX = 500;
var maxY = 500;
describe('maxX only', function() {
it('returns bounds for horizontal image', function() {
var bounds = aspect.resize(horizontal.x, horizontal.y, maxX);
assert.deepEqual(bounds, [ 500, 333 ]);
});
it('returns bounds for vertical image', function() {
var bounds = aspect.resize(vertical.x, vertical.y, maxX);
assert.deepEqual(bounds, [ 500, 750 ]);
});
});
describe('maxY only', function() {
it('returns bounds for horizontal image', function() {
var bounds = aspect.resize(horizontal.x, horizontal.y, undefined, maxY);
assert.deepEqual(bounds, [ 750, 500 ]);
});
it('returns bounds for vertical image', function() {
var bounds = aspect.resize(vertical.x, vertical.y, undefined, maxY);
assert.deepEqual(bounds, [ 333, 500 ]);
});
});
describe('maxX and maxY', function() {
it('returns bounds for horizontal image', function() {
var bounds = aspect.resize(horizontal.x, horizontal.y, 500, 500);
assert.deepEqual(bounds, [ 500, 333 ]);
});
it('returns bounds for vertical image', function() {
var bounds = aspect.resize(vertical.x, vertical.y, 500, 500);
assert.deepEqual(bounds, [ 333, 500 ]);
});
it('properly rounds all edges', function() {
var bounds = aspect.resize(800, 534, 500, 500);
assert.deepEqual(bounds, [ 500, 334 ]);
});
});
});
describe('horizontal image', function() {
// 5184 × 3456
var width = 5184;
var height = 3456;
describe('same orientation', function() {
it('returns crop for 1:1 aspect ratio', function() {
// 3456 × 3456
var crop = aspect.crop(width, height, '1:1');
assert.deepEqual(crop, [ 864, 0, 3456, 3456 ]);
});
it('returns crop for 3:2 aspect ratio', function() {
// 5184 × 3456
var crop = aspect.crop(width, height, '3:2');
assert.deepEqual(crop, [ 0, 0, 5184, 3456 ]);
});
it('returns crop for 3:5 aspect ratio', function() {
// 5184 × 3110
var crop = aspect.crop(width, height, '3:5');
assert.deepEqual(crop, [ 0, 172, 5184, 3112 ]);
});
it('returns crop for 4:3 aspect ratio', function() {
// 4608 × 3456
var crop = aspect.crop(width, height, '4:3');
assert.deepEqual(crop, [ 288, 0, 4608, 3456 ]);
});
it('returns crop for 5:7 aspect ratio', function() {
// 4838 × 3456
var crop = aspect.crop(width, height, '5:7');
assert.deepEqual(crop, [ 172, 0, 4840, 3456 ]);
});
it('returns crop for 8:10 aspect ratio', function() {
// 4320 × 3456
var crop = aspect.crop(width, height, '8:10');
assert.deepEqual(crop, [ 1209, 0, 2766, 3456 ]);
});
it('returns crop for 16:9 aspect ratio', function() {
// 5184 × 2916
var crop = aspect.crop(width, height, '16:9');
assert.deepEqual(crop, [ 0, 270, 5184, 2916 ]);
});
});
describe('vertical orientation', function() {
it('returns crop for 1:1 aspect ratio', function() {
// 3456 × 3456
var crop = aspect.crop(width, height, '1:1!v');
assert.deepEqual(crop, [ 864, 0, 3456, 3456 ]);
});
it('returns crop for 3:2 aspect ratio', function() {
// 2304 × 3456
var crop = aspect.crop(width, height, '3:2!v');
assert.deepEqual(crop, [ 1440, 0, 2304, 3456 ]);
});
it('returns crop for 3:5 aspect ratio', function() {
// 2074 × 3456
var crop = aspect.crop(width, height, '3:5!v');
assert.deepEqual(crop, [ 1555, 0, 2074, 3456 ]);
});
it('returns crop for 4:3 aspect ratio', function() {
// 2592 × 3456
var crop = aspect.crop(width, height, '4:3!v');
assert.deepEqual(crop, [ 1296, 0, 2592, 3456 ]);
});
it('returns crop for 5:7 aspect ratio', function() {
// 2469 × 3456
var crop = aspect.crop(width, height, '5:7!v');
assert.deepEqual(crop, [ 1357, 0, 2470, 3456 ]);
});
it('returns crop for 8:10 aspect ratio', function() {
// 2765 × 3456
var crop = aspect.crop(width, height, '8:10!v');
assert.deepEqual(crop, [ 1209, 0, 2766, 3456 ]);
});
it('returns crop for 16:9 aspect ratio', function() {
// 1944 × 3456
var crop = aspect.crop(width, height, '16:9!v');
assert.deepEqual(crop, [ 1620, 0, 1944, 3456 ]);
});
});
});
describe('vertical image', function() {
// 3456 x 5184
var width = 3456;
var height = 5184;
describe('same orientation', function() {
it('returns crop for 1:1 aspect ratio', function() {
// 3456 × 3456
var crop = aspect.crop(width, height, '1:1');
assert.deepEqual(crop, [ 0, 864, 3456, 3456 ]);
});
it('returns crop for 3:2 aspect ratio', function() {
// 5184 × 3456
var crop = aspect.crop(width, height, '3:2');
assert.deepEqual(crop, [ 0, 0, 3456, 5184 ]);
});
it('returns crop for 3:5 aspect ratio', function() {
// 5184 × 3110
var crop = aspect.crop(width, height, '3:5');
assert.deepEqual(crop, [ 172, 0, 3112, 5184 ]);
});
it('returns crop for 4:3 aspect ratio', function() {
// 4608 × 3456
var crop = aspect.crop(width, height, '4:3');
assert.deepEqual(crop, [ 0, 288, 3456, 4608 ]);
});
it('returns crop for 5:7 aspect ratio', function() {
// 4838 × 3456
var crop = aspect.crop(width, height, '5:7');
assert.deepEqual(crop, [ 0, 172, 3456, 4840 ]);
});
it('returns crop for 8:10 aspect ratio', function() {
// 4320 × 3456
var crop = aspect.crop(width, height, '8:10');
assert.deepEqual(crop, [ 0, 1209, 3456, 2766 ]);
});
it('returns crop for 16:9 aspect ratio', function() {
// 5184 × 2916
var crop = aspect.crop(width, height, '16:9');
assert.deepEqual(crop, [ 270, 0, 2916, 5184 ]);
});
});
describe('horizontal orientation', function() {
it('returns crop for 1:1 aspect ratio', function() {
// 3456 × 3456
var crop = aspect.crop(width, height, '1:1!h');
assert.deepEqual(crop, [ 0, 864, 3456, 3456 ]);
});
it('returns crop for 3:2 aspect ratio', function() {
// 3456 × 2304
var crop = aspect.crop(width, height, '3:2!h');
assert.deepEqual(crop, [ 0, 1440, 3456, 2304 ]);
});
it('returns crop for 3:5 aspect ratio', function() {
// 3456 × 2074
var crop = aspect.crop(width, height, '3:5!h');
assert.deepEqual(crop, [ 0, 1555, 3456, 2074 ]);
});
it('returns crop for 4:3 aspect ratio', function() {
// 3456 × 2592
var crop = aspect.crop(width, height, '4:3!h');
assert.deepEqual(crop, [ 0, 1296, 3456, 2592 ]);
});
it('returns crop for 5:7 aspect ratio', function() {
// 3456 × 2469
var crop = aspect.crop(width, height, '5:7!h');
assert.deepEqual(crop, [ 0, 1357, 3456, 2470 ]);
});
it('returns crop for 8:10 aspect ratio', function() {
// 3456 × 2765
var crop = aspect.crop(width, height, '8:10!h');
assert.deepEqual(crop, [ 0, 1209, 3456, 2766 ]);
});
it('returns crop for 16:9 aspect ratio', function() {
// 3456 × 1944
var crop = aspect.crop(width, height, '16:9!h');
assert.deepEqual(crop, [ 0, 1620, 3456, 1944 ]);
});
});
});