Render in the created temporry directory

This commit is contained in:
Mohammad Fares 2023-07-09 12:29:12 +02:00
parent 1a75305ea8
commit 2533271eca
1 changed files with 7 additions and 9 deletions

View File

@ -5,6 +5,10 @@
* @author Mohammad Fares <faressoft.com@gmail.com> * @author Mohammad Fares <faressoft.com@gmail.com>
*/ */
const tmp = require('tmp');
tmp.setGracefulCleanup();
/** /**
* The directory to render the frames into * The directory to render the frames into
*/ */
@ -85,7 +89,7 @@ function loadPNG(path) {
*/ */
function getFrameDimensions() { function getFrameDimensions() {
// The path of the first rendered frame // The path of the first rendered frame
var framePath = di.path.join(ROOT_PATH, "render/frames/0.png"); var framePath = di.path.join(renderDir, "0.png");
// Read and parse a PNG image file // Read and parse a PNG image file
return loadPNG(framePath).then(function (png) { return loadPNG(framePath).then(function (png) {
@ -95,7 +99,6 @@ function getFrameDimensions() {
}; };
}); });
} }
/** /**
* Render the frames into PNG images * Render the frames into PNG images
* *
@ -210,7 +213,6 @@ function mergeFrames(records, options, frameDimensions) {
// Write the headers // Write the headers
gif.writeHeader(); gif.writeHeader();
// Foreach frame
di.async.eachOfSeries( di.async.eachOfSeries(
records, records,
function (frame, index, callback) { function (frame, index, callback) {
@ -222,11 +224,7 @@ function mergeFrames(records, options, frameDimensions) {
stepsCounter = (stepsCounter + 1) % options.step; stepsCounter = (stepsCounter + 1) % options.step;
// The path of the rendered frame // The path of the rendered frame
var framePath = di.path.join( var framePath = di.path.join(renderDir, index + ".png");
ROOT_PATH,
"render/frames",
index + ".png"
);
// Read and parse the rendered frame // Read and parse the rendered frame
loadPNG(framePath) loadPNG(framePath)