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
import { tidbytCheck } from "https://esm.town/v/andreterron/tidbytCheck";
import { tidbytCircle } from "https://esm.town/v/andreterron/tidbytCircle";
import { tidbytSkipped } from "https://esm.town/v/andreterron/tidbytSkipped";
import { tidbytStar } from "https://esm.town/v/andreterron/tidbytStar";
import { tidbytX } from "https://esm.town/v/andreterron/tidbytX";
import { workoutDays as workoutDays2 } from "https://esm.town/v/andreterron/workoutDays";
import { WorkoutIcon } from "https://esm.town/v/andreterron/workoutIcons";
import Jimp from "npm:jimp@0";
export async function createTidbytWorkoutsImage(icons: WorkoutIcon[]) {
const headerUrl = "https://art.pixilart.com/sr2c714c74a22aws3.png";
const weekdaysUrl = "https://art.pixilart.com/sr22f1df42b42aws3.png";
const img = await new Jimp(64, 32, 0x000000ff);
const header = await Jimp.read(headerUrl);
const weekdays = await Jimp.read(weekdaysUrl);
await img
.composite(
await header
.resize(64, 32),
0,
0,
)
.composite(
await weekdays
.resize(64, 32),
0,
0,
{
mode: Jimp.BLEND_SOURCE_OVER,
opacitySource: 0.5,
opacityDest: 1,
},
);
const checked = await tidbytCheck({
size: 7,
});
const unchecked = await tidbytCircle({
size: 7,
border: 0xffffff80,
});
const skipped = await tidbytSkipped({
size: 7,
});
const failed = await tidbytX({
size: 7,
});
const today = await tidbytCircle({
size: 7,
border: 0xffffffff,
});
const star = await tidbytStar({
size: 7,
border: 0xffffffff,
});
function selectIcon(icon: WorkoutIcon) {
switch (icon) {
case "done":
return checked;
case "failed":
return failed;
case "skipped":
return skipped;
case "today":
return today;
case "future":
return unchecked;
case "star":
return star;
}
}
for (let i = 0; i < 7; i++) {
await img.composite(
selectIcon(icons[i]),
1 + i * 9,
31 - 5 - 7,
);
}
return await img
.resize(64, 32);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
September 12, 2024