0

I'm trying to use the merge-images script (https://github.com/lukechilds/merge-images) to merge some images into a single one using nodejs.

I'm having trouble understanding what ecatly I'm supposed to provide in the then() method of mergeImages.

This is what I have so far:

const mergeImages = require('merge-images');
const { createCanvas, Canvas, Image } = require('canvas');

const width = 2880;
const height = 2880;
var canvas = createCanvas(width, height);
const ctx = canvas.getContext('2d');

var img = new Image();
img.onload = () => ctx.drawImage(img, 0, 0);
img.onerror = err => { throw err }
img.src = './result.png';

mergeImages([
            './lunas_parts/1.png', './lunas_parts/2.png', './lunas_parts/3.png', 
            ], {
  Canvas: Canvas,
  Image: Image
})
  .then(b64 => img = b64);

I do have an empty result.png image in the right location, as well as the 1, 2 and 3 .png files. The console isn't showing any error when I execute the above script, but result.png remains empty after the execution.

Is the canvas image source I'm using in then() not correct? What am I supposed to pass there exactly?

Thanks in advance for any help.

0 Answers0