Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MR414N-ID
GitHub Repository: MR414N-ID/botku2
Path: blob/master/node_modules/@jimp/plugin-rotate/test/rotation.test.js
1126 views
1
import { Jimp, mkJGD } from '@jimp/test-utils';
2
import configure from '@jimp/custom';
3
import blit from '@jimp/plugin-blit';
4
import crop from '@jimp/plugin-crop';
5
import resize from '@jimp/plugin-resize';
6
7
import rotate from '../src';
8
9
const jimp = configure({ plugins: [rotate, blit, crop, resize] }, Jimp);
10
11
describe('Rotate a image with even size', () => {
12
let imgSrc = null;
13
14
before(done => {
15
jimp
16
.read(
17
mkJGD(
18
'▰▴▴▴▪▪▪▰',
19
'▴▴▴▴▪▪▪▪',
20
'▴▴▴▴▪▪▪▪',
21
'▴▴▴▴▪▪▪▪',
22
'▪▪▪▪▴▴▴▴',
23
'▪▪▪▪▴▴▴▴',
24
'▪▪▪▪▴▴▴▴',
25
'▦▪▪▪▴▴▴▦'
26
)
27
)
28
.then(imgJimp => {
29
imgSrc = imgJimp;
30
done();
31
})
32
.catch(done);
33
});
34
35
it('1 degrees', () => {
36
imgSrc
37
.clone()
38
.rotate(1, true)
39
.getJGDSync()
40
.should.be.sameJGD(
41
mkJGD(
42
'▰▴▴▴▪▪▪▰ ',
43
'▴▴▴▴▪▪▪▪ ',
44
'▴▴▴▴▪▪▪▪ ',
45
'▴▴▴▴▪▪▪▪ ',
46
'▪▪▪▪▴▴▴▴ ',
47
'▪▪▪▪▴▴▴▴ ',
48
'▪▪▪▪▴▴▴▴ ',
49
'▦▪▪▪▴▴▴▦ ',
50
' ',
51
' '
52
)
53
);
54
});
55
56
it('91 degrees', () => {
57
imgSrc
58
.clone()
59
.rotate(91, true)
60
.getJGDSync()
61
.should.be.sameJGD(
62
mkJGD(
63
' ',
64
'▰▪▪▪▴▴▴▦ ',
65
'▪▪▪▪▴▴▴▴ ',
66
'▪▪▪▪▴▴▴▴ ',
67
'▪▪▪▪▴▴▴▴ ',
68
'▴▴▴▴▪▪▪▪ ',
69
'▴▴▴▴▪▪▪▪ ',
70
'▴▴▴▴▪▪▪▪ ',
71
'▰▴▴▴▪▪▪▦ ',
72
' '
73
)
74
);
75
});
76
77
it('30 degrees', () => {
78
imgSrc
79
.clone()
80
.rotate(30, true)
81
.getJGDSync()
82
.should.be.sameJGD(
83
mkJGD(
84
' ▰▰ ',
85
' ▪▪▪▪ ',
86
' ▴▪▪▪▪▪ ',
87
'▴▴▴▴▪▪▪▪ ',
88
'▴▴▴▴▪▪▴▴▴ ',
89
'▴▴▴▴▪▴▴▴▴▴ ',
90
' ▴▴▪▪▴▴▴▴▦ ',
91
' ▪▪▪▪▪▴▴▴ ',
92
' ▪▪▪▪▪ ',
93
' ▪▪▪ ',
94
' ▦ ',
95
' '
96
)
97
);
98
});
99
100
it('45 degrees', () => {
101
imgSrc
102
.clone()
103
.rotate(45, true)
104
.getJGDSync()
105
.should.be.sameJGD(
106
mkJGD(
107
' ',
108
' ▰ ',
109
' ▪▪▪ ',
110
' ▪▪▪▪▪ ',
111
' ▴▴▪▪▪▪▴ ',
112
' ▴▴▴▴▪▪▴▴▴ ',
113
'▰▰▴▴▴▴▴▴▴▴▦ ',
114
' ▴▴▴▴▪▪▴▴▴ ',
115
' ▴▴▪▪▪▪▴ ',
116
' ▪▪▪▪▪ ',
117
' ▪▪▪ ',
118
' ▦ ',
119
' ',
120
' '
121
)
122
);
123
});
124
125
it('60 degrees', () => {
126
imgSrc
127
.clone()
128
.rotate(60, true)
129
.getJGDSync()
130
.should.be.sameJGD(
131
mkJGD(
132
' ▰ ',
133
' ▪▪▪ ',
134
' ▪▪▪▪▪ ',
135
' ▪▪▪▪▪▴▴▴ ',
136
' ▴▴▪▪▴▴▴▴▦ ',
137
'▴▴▴▴▪▴▴▴▴▴ ',
138
'▴▴▴▴▪▪▴▴▴ ',
139
'▴▴▴▴▪▪▪▪ ',
140
' ▴▪▪▪▪▪ ',
141
' ▪▪▪▪ ',
142
' ▦▦ ',
143
' '
144
)
145
);
146
});
147
148
it('90 degrees', () => {
149
imgSrc
150
.clone()
151
.rotate(90, true)
152
.getJGDSync()
153
.should.be.sameJGD(
154
mkJGD(
155
' ',
156
'▰▪▪▪▴▴▴▦ ',
157
'▪▪▪▪▴▴▴▴ ',
158
'▪▪▪▪▴▴▴▴ ',
159
'▪▪▪▪▴▴▴▴ ',
160
'▴▴▴▴▪▪▪▪ ',
161
'▴▴▴▴▪▪▪▪ ',
162
'▴▴▴▴▪▪▪▪ ',
163
'▰▴▴▴▪▪▪▦ ',
164
' '
165
)
166
);
167
});
168
169
it('120 degrees', () => {
170
imgSrc
171
.clone()
172
.rotate(120, true)
173
.getJGDSync()
174
.should.be.sameJGD(
175
mkJGD(
176
' ',
177
' ▴▦ ',
178
' ▴▴▴▴ ',
179
' ▪▪▴▴▴▴ ',
180
'▰▪▪▪▴▴▴▴▪ ',
181
'▰▪▪▪▪▴▴▪▪▪ ',
182
' ▪▪▪▪▪▪▪▪▪ ',
183
' ▪▪▴▴▴▪▪▪▪▦ ',
184
' ▴▴▴▴▴▪▪ ',
185
' ▴▴▴▴▪ ',
186
' ▴▴▴ ',
187
' '
188
)
189
);
190
});
191
192
it('135 degrees', () => {
193
imgSrc
194
.clone()
195
.rotate(135, true)
196
.getJGDSync()
197
.should.be.sameJGD(
198
mkJGD(
199
' ',
200
' ',
201
' ▦ ',
202
' ▴▴▴ ',
203
' ▴▴▴▴▴ ',
204
' ▪▪▴▴▴▪▪ ',
205
' ▪▪▪▪▴▪▪▪▪ ',
206
' ▰▪▪▪▪▴▪▪▪▪▦ ',
207
' ▪▪▪▴▴▴▪▪▪ ',
208
' ▪▴▴▴▴▴▪ ',
209
' ▴▴▴▴▴ ',
210
' ▴▰▴ ',
211
' ▰ ',
212
' '
213
)
214
);
215
});
216
217
it('180 degrees', () => {
218
imgSrc
219
.clone()
220
.rotate(180, true)
221
.getJGDSync()
222
.should.be.sameJGD(
223
mkJGD(
224
' ',
225
' ▦▴▴▴▪▪▪▦ ',
226
' ▴▴▴▴▪▪▪▪ ',
227
' ▴▴▴▴▪▪▪▪ ',
228
' ▴▴▴▴▪▪▪▪ ',
229
' ▪▪▪▪▴▴▴▴ ',
230
' ▪▪▪▪▴▴▴▴ ',
231
' ▪▪▪▪▴▴▴▴ ',
232
' ▰▪▪▪▴▴▴▰ ',
233
' '
234
)
235
);
236
});
237
238
it('225 degrees', () => {
239
imgSrc
240
.clone()
241
.rotate(225, true)
242
.getJGDSync()
243
.should.be.sameJGD(
244
mkJGD(
245
' ',
246
' ▦ ',
247
' ▪▪▪ ',
248
' ▪▪▪▪▪ ',
249
' ▴▪▪▪▪▴▴ ',
250
' ▴▴▴▪▪▴▴▴▴ ',
251
' ▦▴▴▴▴▴▴▴▴▰▰ ',
252
' ▴▴▴▪▪▴▴▴▴ ',
253
' ▴▪▪▪▪▴▴ ',
254
' ▪▪▪▪▪ ',
255
' ▪▪▪ ',
256
' ▰ ',
257
' ',
258
' '
259
)
260
);
261
});
262
263
it('270 degrees', () => {
264
imgSrc
265
.clone()
266
.rotate(270, true)
267
.getJGDSync()
268
.should.be.sameJGD(
269
mkJGD(
270
' ▦▪▪▪▴▴▴▰ ',
271
' ▪▪▪▪▴▴▴▴ ',
272
' ▪▪▪▪▴▴▴▴ ',
273
' ▪▪▪▪▴▴▴▴ ',
274
' ▴▴▴▴▪▪▪▪ ',
275
' ▴▴▴▴▪▪▪▪ ',
276
' ▴▴▴▴▪▪▪▪ ',
277
' ▦▴▴▴▪▪▪▰ ',
278
' ',
279
' '
280
)
281
);
282
});
283
284
it('315 degrees', () => {
285
imgSrc
286
.clone()
287
.rotate(315, true)
288
.getJGDSync()
289
.should.be.sameJGD(
290
mkJGD(
291
' ▰ ',
292
' ▴▰▴ ',
293
' ▴▴▴▴▴ ',
294
' ▪▴▴▴▴▴▪ ',
295
' ▪▪▪▴▴▴▪▪▪ ',
296
' ▦▪▪▪▪▴▪▪▪▪▰ ',
297
' ▪▪▪▪▴▪▪▪▪ ',
298
' ▪▪▴▴▴▪▪ ',
299
' ▴▴▴▴▴ ',
300
' ▴▴▴ ',
301
' ▦ ',
302
' ',
303
' ',
304
' '
305
)
306
);
307
});
308
309
it('360 degrees', () => {
310
imgSrc
311
.clone()
312
.rotate(360, true)
313
.getJGDSync()
314
.should.be.sameJGD(
315
mkJGD(
316
'▰▴▴▴▪▪▪▰ ',
317
'▴▴▴▴▪▪▪▪ ',
318
'▴▴▴▴▪▪▪▪ ',
319
'▴▴▴▴▪▪▪▪ ',
320
'▪▪▪▪▴▴▴▴ ',
321
'▪▪▪▪▴▴▴▴ ',
322
'▪▪▪▪▴▴▴▴ ',
323
'▦▪▪▪▴▴▴▦ ',
324
' ',
325
' '
326
)
327
);
328
});
329
});
330
331
describe('Rotate a image with odd size', () => {
332
let imgSrc = null;
333
before(done => {
334
jimp
335
.read(
336
mkJGD(
337
'▴▴▴▦▪▪▪',
338
'▴▴▴▦▪▪▪',
339
'▴▴▴▦▪▪▪',
340
'▦▦▦▦▦▦▦',
341
'▴▴▴▦▴▴▴',
342
'▴▴▴▦▴▴▴',
343
'▴▴▴▦▴▴▴'
344
)
345
)
346
.then(imgJimp => {
347
imgSrc = imgJimp;
348
done();
349
})
350
.catch(done);
351
});
352
353
it('45 degrees', () => {
354
imgSrc
355
.clone()
356
.rotate(45, true)
357
.getJGDSync()
358
.should.be.sameJGD(
359
mkJGD(
360
' ',
361
' ▪ ',
362
' ▪▪▪ ',
363
' ▦▪▪▪▦ ',
364
' ▴▴▦▪▦▴▴ ',
365
' ▴▴▴▴▦▴▴▴▴ ',
366
' ▴▴▦▴▦▴▴ ',
367
' ▦▴▴▴▦ ',
368
' ▴▴▴ ',
369
' ▴ ',
370
' ',
371
' '
372
)
373
);
374
});
375
376
it('135 degrees', () => {
377
imgSrc
378
.clone()
379
.rotate(135, true)
380
.getJGDSync()
381
.should.be.sameJGD(
382
mkJGD(
383
' ',
384
' ▴ ',
385
' ▴▴▴ ',
386
' ▦▴▴▴▦ ',
387
' ▪▪▦▴▦▴▴ ',
388
' ▪▪▪▪▦▴▴▴▴ ',
389
' ▪▪▦▴▦▴▴ ',
390
' ▦▴▴▴▦ ',
391
' ▴▴▴ ',
392
' ▴ ',
393
' ',
394
' '
395
)
396
);
397
});
398
399
it('225 degrees', () => {
400
imgSrc
401
.clone()
402
.rotate(225, true)
403
.getJGDSync()
404
.should.be.sameJGD(
405
mkJGD(
406
' ',
407
' ▴ ',
408
' ▴▴▴ ',
409
' ▦▴▴▴▦ ',
410
' ▴▴▦▴▦▴▴ ',
411
' ▴▴▴▴▦▴▴▴▴ ',
412
' ▴▴▦▪▦▴▴ ',
413
' ▦▪▪▪▦ ',
414
' ▪▪▪ ',
415
' ▪ ',
416
' ',
417
' '
418
)
419
);
420
});
421
422
it('315 degrees', () => {
423
imgSrc
424
.clone()
425
.rotate(315, true)
426
.getJGDSync()
427
.should.be.sameJGD(
428
mkJGD(
429
' ',
430
' ▴ ',
431
' ▴▴▴ ',
432
' ▦▴▴▴▦ ',
433
' ▴▴▦▴▦▪▪ ',
434
' ▴▴▴▴▦▪▪▪▪ ',
435
' ▴▴▦▴▦▪▪ ',
436
' ▦▴▴▴▦ ',
437
' ▴▴▴ ',
438
' ▴ ',
439
' ',
440
' '
441
)
442
);
443
});
444
});
445
446
describe('Rotate a non-square image', () => {
447
let imgSrc = null;
448
before(done => {
449
jimp
450
.read(mkJGD('▴▴▴▴▪▪▪▪', '▴▴▴▴▪▪▪▪', '▦▦▦▦▴▴▴▴', '▦▦▦▦▴▴▴▴'))
451
.then(imgJimp => {
452
imgSrc = imgJimp;
453
done();
454
})
455
.catch(done);
456
});
457
458
it('1 degrees', () => {
459
imgSrc
460
.clone()
461
.rotate(1, true)
462
.getJGDSync()
463
.should.be.sameJGD(
464
mkJGD(
465
'▴▴▴▴▪▪▪▪ ',
466
'▴▴▴▴▪▪▪▪ ',
467
'▦▦▦▦▴▴▴▴ ',
468
'▦▦▦▦▴▴▴▴ ',
469
' ',
470
' '
471
)
472
);
473
});
474
475
it('10 degrees', () => {
476
imgSrc
477
.clone()
478
.rotate(10, true)
479
.getJGDSync()
480
.should.be.sameJGD(
481
mkJGD(
482
' ▪ ',
483
' ▴▴▴▪▪▪▪ ',
484
'▴▴▴▴▪▪▪▴ ',
485
'▴▴▦▦▴▴▴▴ ',
486
'▦▦▦▦▴▴▴ ',
487
'▦▦ ',
488
' ',
489
' '
490
)
491
);
492
});
493
494
it('30 degrees', () => {
495
imgSrc
496
.clone()
497
.rotate(30, true)
498
.getJGDSync()
499
.should.be.sameJGD(
500
mkJGD(
501
' ',
502
' ▪▪ ',
503
' ▪▪▪▪ ',
504
' ▴▴▪▪▴▴▴ ',
505
'▴▴▴▦▴▴▴ ',
506
'▴▴▦▦▴▴ ',
507
'▦▦▦▦ ',
508
' ▦ ',
509
' ',
510
' '
511
)
512
);
513
});
514
515
it('45 degrees', () => {
516
imgSrc
517
.clone()
518
.rotate(45, true)
519
.getJGDSync()
520
.should.be.sameJGD(
521
mkJGD(
522
' ',
523
' ▪▪ ',
524
' ▪▪▪▴ ',
525
' ▴▪▪▴▴▴ ',
526
' ▴▴▴▴▴▴ ',
527
'▴▴▴▦▦▴ ',
528
'▴▴▦▦▦ ',
529
' ▦▦▦ ',
530
' ▦ ',
531
' '
532
)
533
);
534
});
535
536
it('90 degrees', () => {
537
imgSrc
538
.clone()
539
.rotate(90, true)
540
.getJGDSync()
541
.should.be.sameJGD(
542
mkJGD(
543
' ',
544
'▪▪▴▴ ',
545
'▪▪▴▴ ',
546
'▪▪▴▴ ',
547
'▪▪▴▴ ',
548
'▴▴▦▦ ',
549
'▴▴▦▦ ',
550
'▴▴▦▦ ',
551
'▴▴▦▦ ',
552
' '
553
)
554
);
555
});
556
557
it('135 degrees', () => {
558
imgSrc
559
.clone()
560
.rotate(135, true)
561
.getJGDSync()
562
.should.be.sameJGD(
563
mkJGD(
564
' ',
565
' ▴ ',
566
' ▴▴▴ ',
567
' ▪▪▴▴▴ ',
568
' ▪▪▪▴▦▦ ',
569
' ▪▪▴▦▦▦ ',
570
' ▴▴▴▦▦▦ ',
571
' ▴▴▴▦ ',
572
' ▴▴ ',
573
' '
574
)
575
);
576
});
577
578
it('180 degrees', () => {
579
imgSrc
580
.clone()
581
.rotate(180, true)
582
.getJGDSync()
583
.should.be.sameJGD(
584
mkJGD(
585
' ',
586
' ▴▴▴▴▦▦▦▦ ',
587
' ▴▴▴▴▦▦▦▦ ',
588
' ▪▪▪▪▴▴▴▴ ',
589
' ▪▪▪▪▴▴▴▴ ',
590
' '
591
)
592
);
593
});
594
595
it('225 degrees', () => {
596
imgSrc
597
.clone()
598
.rotate(225, true)
599
.getJGDSync()
600
.should.be.sameJGD(
601
mkJGD(
602
' ▦ ',
603
' ▦▦▦ ',
604
' ▦▦▦▴▴ ',
605
' ▴▦▦▴▴▴ ',
606
' ▴▴▴▴▴▴ ',
607
' ▴▴▴▪▪▴ ',
608
' ▴▪▪▪ ',
609
' ▪▪ ',
610
' ',
611
' '
612
)
613
);
614
});
615
616
it('315 degrees', () => {
617
imgSrc
618
.clone()
619
.rotate(315, true)
620
.getJGDSync()
621
.should.be.sameJGD(
622
mkJGD(
623
' ▴▴ ',
624
' ▦▴▴▴ ',
625
'▦▦▦▴▴▴ ',
626
' ▦▦▦▴▪▪ ',
627
' ▦▦▴▪▪▪ ',
628
' ▴▴▴▪▪ ',
629
' ▴▴▴ ',
630
' ▴ ',
631
' ',
632
' '
633
)
634
);
635
});
636
});
637
638