index-node.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { getExportCanvasPreview } from "../src/scene/getExportCanvasPreview";
  2. const { registerFont, createCanvas } = require("canvas");
  3. const elements = [
  4. {
  5. id: "eVzaxG3YnHhqjEmD7NdYo",
  6. type: "diamond",
  7. x: 519,
  8. y: 199,
  9. width: 113,
  10. height: 115,
  11. strokeColor: "#000000",
  12. backgroundColor: "transparent",
  13. fillStyle: "hachure",
  14. strokeWidth: 1,
  15. roughness: 1,
  16. opacity: 100,
  17. isSelected: false,
  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. isSelected: false,
  34. seed: 952056308
  35. },
  36. {
  37. id: "kqKI231mvTrcsYo2DkUsR",
  38. type: "text",
  39. x: 557.5,
  40. y: 317.5,
  41. width: 43,
  42. height: 31,
  43. strokeColor: "#000000",
  44. backgroundColor: "transparent",
  45. fillStyle: "hachure",
  46. strokeWidth: 1,
  47. roughness: 1,
  48. opacity: 100,
  49. isSelected: false,
  50. seed: 1683771448,
  51. text: "test",
  52. font: "20px Virgil",
  53. baseline: 22
  54. }
  55. ];
  56. registerFont("./public/FG_Virgil.ttf", { family: "Virgil" });
  57. const canvas = getExportCanvasPreview(
  58. elements as any,
  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", () => console.log("test.png was created."));