Create a PNG image using node.js

Is it possible to create a PNG image from an array of pixel data using Node.js? I would like to create a PNG image from an array of RGBA values ​​and then save it to a file.

+4
source share
1 answer

You can use jimp .

const Jimp = require('Jimp'); let imageData = [ [ 0xFF0000FF, 0xFF0000FF, 0xFF0000FF ], [ 0xFF0000FF, 0x00FF00FF, 0xFF0000FF ], [ 0xFF0000FF, 0xFF0000FF, 0x0000FFFF ] ]; let image = new Jimp(3, 3, function (err, image) { if (err) throw err; imageData.forEach((row, y) => { row.forEach((color, x) => { image.setPixelColor(color, x, y); }); }); image.write('test.png', (err) => { if (err) throw err; }); }); 

This code creates a 3x3 pixel png file with specific array colors.

+4
source

Source: https://habr.com/ru/post/1433694/


All Articles