-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-sheet.mjs
More file actions
43 lines (37 loc) · 1.02 KB
/
Copy pathmake-sheet.mjs
File metadata and controls
43 lines (37 loc) · 1.02 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
#!/usr/bin/env node
import sharp from 'sharp';
import { parseArgs } from 'node:util';
const { values, positionals } = parseArgs({
options: {
out: { type: 'string' },
},
allowPositionals: true,
});
if (!values.out || positionals.length === 0) {
console.error('Usage: node scripts/make-sheet.mjs --out sheet.png frame1.png frame2.png ...');
process.exit(1);
}
const frames = positionals;
const firstMeta = await sharp(frames[0]).metadata();
const w = firstMeta.width;
const h = firstMeta.height;
const composites = [];
for (let i = 0; i < frames.length; i++) {
composites.push({
input: await sharp(frames[i]).resize(w, h).toBuffer(),
left: i * w,
top: 0,
});
}
await sharp({
create: {
width: w * frames.length,
height: h,
channels: 4,
background: { r: 0, g: 0, b: 0, alpha: 0 },
},
})
.composite(composites)
.png()
.toFile(values.out);
console.log(`Saved: ${values.out} (${frames.length} frames, ${w}x${h} each)`);