MZ How to bake multiple pngs into one file and save

Hello fellow RPG Makers!

I'm working on a character customization system and am having trouble saving the character. The character is composed of three layered images that need to be baked into one PNG that can be stored in the pictures folder. I have tried using the merge-images npm package in a mjs file which works outside the engine (in Node.js), but I can't get it to work in the engine. Any help would be greatly appreciated!
You can use canvas. But I need to know how your 3 images are coded to know how to write it.
It is something like this:
JavaScript:
var canvas = document.createElement('canvas');
canvas.width=1000;
canvas.height=1000;
var ctx = canvas.getContext("2d");

ctx.drawImage(image1, 0, 0);
ctx.drawImage(image2, 0, 0);
ctx.drawImage(image3, 0, 0);

fs = require('fs')
fs.writeFileSync('img/picutres/custompicture.png', canvas.toDataURL().replace(/^data:image\/(png|jpg|jpeg);base64,/, ""), 'base64');
Thanks for the reply! I'm using 3 layers for the character with different options for the body, hair, and facial expression. The format of the file names is something like this for simplicity:

Layer 1 (Bottom): BodyGender#.png (Replace 'Gender' with actual gender and # with skin tone, both dictated by game variables)
Layer 2: Expression_1.png (Not dictated by player choice so just need to run a loop to generate the same character with different expressions)
Layer 3 (Top): HairColour_#.png (Replace 'Colour' with actual hair colour and # with hairstyle, both dictated by game variables)

I was planning on using literals to designate the appropriate files to load and I'm just going to call it using a plugin command. Other than that there's not much else to it.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-bake-multiple-pngs-into-one-file-and-save.170892/