From 1aacc415f8dd291516efb4a4d9a7c170a5e9ba3f Mon Sep 17 00:00:00 2001 From: Roderick Ford Date: Sun, 20 Feb 2022 18:57:33 -0700 Subject: [PATCH 1/2] use nodejs createCanvas --- save-pixels.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/save-pixels.js b/save-pixels.js index 9efce4d..8c3e8b2 100644 --- a/save-pixels.js +++ b/save-pixels.js @@ -124,10 +124,8 @@ module.exports = function savePixels (array, type, options) { return png.pack() case 'CANVAS': - var canvas = document.createElement('canvas') + var canvas = createCanvas(array.shape[0], array.shape[1]); var context = canvas.getContext('2d') - canvas.width = array.shape[0] - canvas.height = array.shape[1] var imageData = context.getImageData(0, 0, canvas.width, canvas.height) var data = imageData.data data = handleData(array, data) From 4e501bfba57b656c83ed15fc4666fd9fcb0978ca Mon Sep 17 00:00:00 2001 From: Roderick Ford Date: Tue, 22 Feb 2022 19:11:41 -0700 Subject: [PATCH 2/2] import canvas --- package.json | 1 + save-pixels.js | 1 + 2 files changed, 2 insertions(+) diff --git a/package.json b/package.json index 36ad5e0..042526f 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "test": "test" }, "dependencies": { + "canvas": "^2.9.0", "contentstream": "^1.0.0", "gif-encoder": "~0.4.1", "jpeg-js": "^0.4.3", diff --git a/save-pixels.js b/save-pixels.js index 8c3e8b2..8fe46d8 100644 --- a/save-pixels.js +++ b/save-pixels.js @@ -7,6 +7,7 @@ var PNG = require('pngjs-nozlib').PNG var ndarray = require('ndarray') var ops = require('ndarray-ops') var through = require('through') +var createCanvas = require('canvas').createCanvas function handleData (array, data, frame) { var i, j, ptr = 0, c