excalidraw/src/index-node.ts

83 lines
1.7 KiB
TypeScript
Raw Normal View History

import { exportToCanvas } from "./scene/export";
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
];
registerFont("./public/FG_Virgil.ttf", { family: "Virgil" });
registerFont("./public/Cascadia.ttf", { family: "Cascadia" });
const canvas = exportToCanvas(
2020-01-19 13:21:33 -08:00
elements as any,
{
...getDefaultAppState(),
offsetTop: 0,
offsetLeft: 0,
},
2020-01-19 13:21:33 -08:00
{
exportBackground: true,
viewBackgroundColor: "#ffffff",
shouldAddWatermark: false,
2020-01-24 12:04:54 +02:00
scale: 1,
2020-01-19 13:21:33 -08:00
},
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");
const stream = canvas.createPNGStream();
stream.pipe(out);
out.on("finish", () => {
console.info("test.png was created.");
});