feat: add png node script
This commit is contained in:
parent
335fe429fd
commit
31bee1a219
2 changed files with 24 additions and 2 deletions
|
@ -66,6 +66,7 @@
|
||||||
"standard-version": "^9.5.0",
|
"standard-version": "^9.5.0",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"tsup": "^6.7.0",
|
"tsup": "^6.7.0",
|
||||||
"typescript": "^5.0.4"
|
"typescript": "^5.0.4",
|
||||||
|
"canvas": "^2.11.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import { createCanvas } from "canvas";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import { variants } from "@catppuccin/palette";
|
import { variants } from "@catppuccin/palette";
|
||||||
import url from "url";
|
import url from "url";
|
||||||
|
@ -75,11 +76,27 @@ const generateSip = (name, palette) => {
|
||||||
return JSON.stringify(data, null, 2);
|
return JSON.stringify(data, null, 2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const generatePng = (name, palette) => {
|
||||||
|
const colors = Object.entries(palette).map(([key, value]) => value.hex);
|
||||||
|
const size = 25;
|
||||||
|
const width = size * colors.length;
|
||||||
|
const canvas = createCanvas(width, size * 2);
|
||||||
|
const ctx = canvas.getContext("2d");
|
||||||
|
|
||||||
|
for (let x = 0; x < width; x += size) {
|
||||||
|
const index = (x / size) % colors.length;
|
||||||
|
ctx.fillStyle = `#${colors[index]}`;
|
||||||
|
ctx.fillRect(x, 0, size, size * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return canvas.toBuffer("image/png");
|
||||||
|
};
|
||||||
|
|
||||||
Object.entries(variants).map(async ([name, palette]) => {
|
Object.entries(variants).map(async ([name, palette]) => {
|
||||||
// formatted "pretty" name, Catppuccin <Flavor>
|
// formatted "pretty" name, Catppuccin <Flavor>
|
||||||
const pname = `Catppuccin ${name.charAt(0).toUpperCase() + name.slice(1)}`;
|
const pname = `Catppuccin ${name.charAt(0).toUpperCase() + name.slice(1)}`;
|
||||||
|
|
||||||
["gimp", "procreate", "sip"].map((folder) =>
|
["gimp", "procreate", "sip", "png"].map((folder) =>
|
||||||
fs.mkdirSync(path.join(root, folder), { recursive: true })
|
fs.mkdirSync(path.join(root, folder), { recursive: true })
|
||||||
);
|
);
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
|
@ -94,4 +111,8 @@ Object.entries(variants).map(async ([name, palette]) => {
|
||||||
path.resolve(root, `sip/${pname}.palette`),
|
path.resolve(root, `sip/${pname}.palette`),
|
||||||
generateSip(pname, palette)
|
generateSip(pname, palette)
|
||||||
);
|
);
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.resolve(root, `png/${pname}.png`),
|
||||||
|
generatePng(pname, palette)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue