2020-01-28 12:25:13 -08:00
|
|
|
import { exportToCanvas } from "./scene/export";
|
2020-03-08 10:20:55 -07:00
|
|
|
import { getDefaultAppState } from "./appState";
|
2020-01-19 13:21:33 -08:00
|
|
|
|
|
|
|
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,
|
2020-01-24 12:04:54 +02:00
|
|
|
seed: 749612521,
|
2020-01-19 13:21:33 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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,
|
2020-01-24 12:04:54 +02:00
|
|
|
seed: 952056308,
|
2020-01-19 13:21:33 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
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",
|
2020-01-24 12:04:54 +02:00
|
|
|
baseline: 22,
|
|
|
|
},
|
2020-01-19 13:21:33 -08:00
|
|
|
];
|
|
|
|
|
2021-02-28 14:22:32 +02:00
|
|
|
registerFont("./public/Virgil.woff2", { family: "Virgil" });
|
|
|
|
registerFont("./public/Cascadia.woff2", { family: "Cascadia" });
|
2020-04-13 16:08:39 +02:00
|
|
|
|
2020-01-28 12:25:13 -08:00
|
|
|
const canvas = exportToCanvas(
|
2020-01-19 13:21:33 -08:00
|
|
|
elements as any,
|
2020-07-27 17:18:49 +05:30
|
|
|
{
|
|
|
|
...getDefaultAppState(),
|
|
|
|
offsetTop: 0,
|
|
|
|
offsetLeft: 0,
|
2021-04-04 15:05:16 +05:30
|
|
|
width: 0,
|
|
|
|
height: 0,
|
2020-07-27 17:18:49 +05:30
|
|
|
},
|
2021-10-21 22:05:48 +02:00
|
|
|
{}, // files
|
2020-01-19 13:21:33 -08:00
|
|
|
{
|
|
|
|
exportBackground: true,
|
|
|
|
viewBackgroundColor: "#ffffff",
|
|
|
|
},
|
2020-01-24 12:04:54 +02:00
|
|
|
createCanvas,
|
2020-01-19 13:21:33 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
const fs = require("fs");
|
|
|
|
const out = fs.createWriteStream("test.png");
|
2020-10-13 14:47:07 +02:00
|
|
|
const stream = (canvas as any).createPNGStream();
|
2020-01-19 13:21:33 -08:00
|
|
|
stream.pipe(out);
|
2020-01-22 15:13:00 +01:00
|
|
|
out.on("finish", () => {
|
|
|
|
console.info("test.png was created.");
|
|
|
|
});
|