-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpsd.ts
37 lines (30 loc) · 761 Bytes
/
psd.ts
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
import fs from "fs";
import CANVAS from "canvas";
import PSD from "psd";
import psdfile from "./assets/assets.psd";
const sources = {};
const psd = PSD.fromFile(psdfile);
psd.parse();
psd.tree().descendants().forEach(node => {
if (node.type === "layer") {
let name = node.name;
let parent = node.parent;
while (parent) {
name = `${parent.name}-${name}`;
parent = node.parent;
// skip "unused" layers
if (
name.indexOf("unused") >= 0 ||
parent.isGroup() ||
parent.isRoot()
) {
break;
}
}
const image = node.toPng();
if (image.width > 0 && image.height > 0) {
sources[name] = image;
}
}
});
export const mazmorra = await bundle.spritesheet(sources);