index-node.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { exportToCanvas } from "./scene/export";
  2. import { getDefaultAppState } from "./appState";
  3. const { registerFont, createCanvas } = require("canvas");
  4. const elements = [
  5. {
  6. id: "eVzaxG3YnHhqjEmD7NdYo",
  7. type: "diamond",
  8. x: 519,
  9. y: 199,
  10. width: 113,
  11. height: 115,
  12. strokeColor: "#000000",
  13. backgroundColor: "transparent",
  14. fillStyle: "hachure",
  15. strokeWidth: 1,
  16. roughness: 1,
  17. opacity: 100,
  18. seed: 749612521,
  19. },
  20. {
  21. id: "7W-iw5pEBPTU3eaCaLtFo",
  22. type: "ellipse",
  23. x: 552,
  24. y: 238,
  25. width: 49,
  26. height: 44,
  27. strokeColor: "#000000",
  28. backgroundColor: "transparent",
  29. fillStyle: "hachure",
  30. strokeWidth: 1,
  31. roughness: 1,
  32. opacity: 100,
  33. seed: 952056308,
  34. },
  35. {
  36. id: "kqKI231mvTrcsYo2DkUsR",
  37. type: "text",
  38. x: 557.5,
  39. y: 317.5,
  40. width: 43,
  41. height: 31,
  42. strokeColor: "#000000",
  43. backgroundColor: "transparent",
  44. fillStyle: "hachure",
  45. strokeWidth: 1,
  46. roughness: 1,
  47. opacity: 100,
  48. seed: 1683771448,
  49. text: "test",
  50. font: "20px Virgil",
  51. baseline: 22,
  52. },
  53. ];
  54. registerFont("./public/FG_Virgil.ttf", { family: "Virgil" });
  55. registerFont("./public/Cascadia.ttf", { family: "Cascadia" });
  56. const canvas = exportToCanvas(
  57. elements as any,
  58. getDefaultAppState(),
  59. {
  60. exportBackground: true,
  61. viewBackgroundColor: "#ffffff",
  62. scale: 1,
  63. },
  64. createCanvas,
  65. );
  66. const fs = require("fs");
  67. const out = fs.createWriteStream("test.png");
  68. const stream = canvas.createPNGStream();
  69. stream.pipe(out);
  70. out.on("finish", () => {
  71. console.info("test.png was created.");
  72. });