You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
1.7 KiB
TypeScript
84 lines
1.7 KiB
TypeScript
5 years ago
|
import { exportToCanvas } from "./scene/export";
|
||
5 years ago
|
import { getDefaultAppState } from "./appState";
|
||
5 years ago
|
|
||
|
const { registerFont, createCanvas } = require("canvas");
|
||
|
|
||
|
const elements = [
|
||
|
{
|
||
|
id: "eVzaxG3YnHhqjEmD7NdYo",
|
||
|
type: "diamond",
|
||
|
x: 519,
|
||
|
y: 199,
|
||
|
width: 113,
|
||
|
height: 115,
|
||
|
strokeColor: "#000000",
|
||
|
backgroundColor: "transparent",
|
||
|
fillStyle: "hachure",
|
||
|
strokeWidth: 1,
|
||
|
roughness: 1,
|
||
|
opacity: 100,
|
||
5 years ago
|
seed: 749612521,
|
||
5 years ago
|
},
|
||
|
{
|
||
|
id: "7W-iw5pEBPTU3eaCaLtFo",
|
||
|
type: "ellipse",
|
||
|
x: 552,
|
||
|
y: 238,
|
||
|
width: 49,
|
||
|
height: 44,
|
||
|
strokeColor: "#000000",
|
||
|
backgroundColor: "transparent",
|
||
|
fillStyle: "hachure",
|
||
|
strokeWidth: 1,
|
||
|
roughness: 1,
|
||
|
opacity: 100,
|
||
5 years ago
|
seed: 952056308,
|
||
5 years ago
|
},
|
||
|
{
|
||
|
id: "kqKI231mvTrcsYo2DkUsR",
|
||
|
type: "text",
|
||
|
x: 557.5,
|
||
|
y: 317.5,
|
||
|
width: 43,
|
||
|
height: 31,
|
||
|
strokeColor: "#000000",
|
||
|
backgroundColor: "transparent",
|
||
|
fillStyle: "hachure",
|
||
|
strokeWidth: 1,
|
||
|
roughness: 1,
|
||
|
opacity: 100,
|
||
|
seed: 1683771448,
|
||
|
text: "test",
|
||
|
font: "20px Virgil",
|
||
5 years ago
|
baseline: 22,
|
||
|
},
|
||
5 years ago
|
];
|
||
|
|
||
4 years ago
|
registerFont("./public/Virgil.woff2", { family: "Virgil" });
|
||
|
registerFont("./public/Cascadia.woff2", { family: "Cascadia" });
|
||
5 years ago
|
|
||
5 years ago
|
const canvas = exportToCanvas(
|
||
5 years ago
|
elements as any,
|
||
5 years ago
|
{
|
||
|
...getDefaultAppState(),
|
||
|
offsetTop: 0,
|
||
|
offsetLeft: 0,
|
||
4 years ago
|
width: 0,
|
||
|
height: 0,
|
||
5 years ago
|
},
|
||
3 years ago
|
{}, // files
|
||
5 years ago
|
{
|
||
|
exportBackground: true,
|
||
|
viewBackgroundColor: "#ffffff",
|
||
|
},
|
||
5 years ago
|
createCanvas,
|
||
5 years ago
|
);
|
||
|
|
||
|
const fs = require("fs");
|
||
|
const out = fs.createWriteStream("test.png");
|
||
4 years ago
|
const stream = (canvas as any).createPNGStream();
|
||
5 years ago
|
stream.pipe(out);
|
||
5 years ago
|
out.on("finish", () => {
|
||
|
console.info("test.png was created.");
|
||
|
});
|