Skip to content

Commit

Permalink
Properly destroy PIXI Application after bitmap generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed Apr 26, 2024
1 parent df9fae0 commit 98e2652
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "card-printing-worker",
"version": "1.5.1",
"version": "1.6.0",
"description": "Printing Worker for Leosac Credential Provisioning solution",
"main": "src/run.js",
"scripts": {
Expand All @@ -25,7 +25,7 @@
},
"homepage": "https://github.com/leosac/card-printing-worker#readme",
"dependencies": {
"@leosac/cardrendering": "^1.6.2",
"@leosac/cardrendering": "^1.7.2",
"@pixi/node": "7.1.3",
"body-parser": "^1.20.2",
"canvas": "^2.11.0",
Expand Down
14 changes: 12 additions & 2 deletions src/services/RenderService.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class RenderService {
async generateImage(layout, sidetpl, data) {
this.logger.info("Generating image...");

const app = new PIXI.Application();
const app = new PIXI.Application({
antialias: true,
autoDensity: true,
resolution: 1
});
const cr = new CardRenderer({
renderer: app.renderer,
stage: app.stage,
Expand All @@ -49,8 +53,14 @@ class RenderService {
await cr.setCardData(data);
}
cr.animate();

const base64img = app.renderer.extract.canvas(app.stage).toDataURL('image/png');

app.stop();
cr.graphics.renderer = undefined; // to avoid rendering on animate function
cr.graphics.card = undefined;
app.destroy(true, { children: true, texture: false, baseTexture: false });

return this.dataURItoBlob(base64img);
}
}
Expand Down

0 comments on commit 98e2652

Please sign in to comment.