-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathrotate.js
More file actions
89 lines (68 loc) · 3.28 KB
/
rotate.js
File metadata and controls
89 lines (68 loc) · 3.28 KB
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
const fs = require('fs').promises;
const {Image} = require('../ImageScript');
const panic = msg => {
console.error(msg);
process.exit(1);
}
(async () => {
{
const binary = await fs.readFile('./tests/targets/image.png');
const image = await Image.decode(binary);
image.rotate(45);
const encoded = await image.encode(1, {creationTime: 0, software: ''});
if (process.env.OVERWRITE_TEST)
await fs.writeFile('./tests/targets/rotate-45.png', encoded);
await fs.writeFile('./tests/targets/rotate-45.png', encoded);
const target = await fs.readFile('./tests/targets/rotate-45.png');
if (!Buffer.from(target).equals(Buffer.from(encoded))) panic('rotate 45 failed');
}
{
const binary = await fs.readFile('./tests/targets/image.png');
const image = await Image.decode(binary);
image.rotate(45, false);
const encoded = await image.encode(1, {creationTime: 0, software: ''});
if (process.env.OVERWRITE_TEST)
await fs.writeFile('./tests/targets/rotate-45-noresize.png', encoded);
const target = await fs.readFile('./tests/targets/rotate-45-noresize.png');
if (!Buffer.from(target).equals(Buffer.from(encoded))) panic('rotate 45 noresize failed');
}
{
const binary = await fs.readFile('./tests/targets/image.png');
const image = await Image.decode(binary);
image.rotate(90);
const encoded = await image.encode(1, {creationTime: 0, software: ''});
if (process.env.OVERWRITE_TEST)
await fs.writeFile('./tests/targets/rotate-90.png', encoded);
await fs.writeFile('./tests/targets/rotate-90.png', encoded);
const target = await fs.readFile('./tests/targets/rotate-90.png');
if (!Buffer.from(target).equals(Buffer.from(encoded))) panic('rotate 90 failed');
}
{
const binary = await fs.readFile('./tests/targets/image.png');
const image = await Image.decode(binary);
image.rotate(180);
const encoded = await image.encode(1, {creationTime: 0, software: ''});
if (process.env.OVERWRITE_TEST)
await fs.writeFile('./tests/targets/rotate-180.png', encoded);
await fs.writeFile('./tests/targets/rotate-180.png', encoded);
const target = await fs.readFile('./tests/targets/rotate-180.png');
if (!Buffer.from(target).equals(Buffer.from(encoded))) panic('rotate 180 failed');
}
{
const binary = await fs.readFile('./tests/targets/image.png');
const image = await Image.decode(binary);
image.rotate(270);
const encoded = await image.encode(1, {creationTime: 0, software: ''});
if (process.env.OVERWRITE_TEST)
await fs.writeFile('./tests/targets/rotate-270.png', encoded);
await fs.writeFile('./tests/targets/rotate-270.png', encoded);
const target = await fs.readFile('./tests/targets/rotate-270.png');
if (!Buffer.from(target).equals(Buffer.from(encoded))) panic('rotate 270 failed');
}
{
const image = new Image(512, 512);
image.fill((x) => Image.hslToColor(x / image.width, 1, .5));
if (!Buffer.from(image.bitmap).equals(Buffer.from(image.rotate(360).bitmap)))
panic('rotate 360 failed');
}
})();