Skip to content

Instantly share code, notes, and snippets.

@6londe
Created September 4, 2022 12:04
Show Gist options
  • Save 6londe/1b201d59243c3b180696eaa7ecc32847 to your computer and use it in GitHub Desktop.
Save 6londe/1b201d59243c3b180696eaa7ecc32847 to your computer and use it in GitHub Desktop.
const imagemagick = require('imagemagick');
const rootPath = require('app-root-path');
const compositeImage = async (imageName, imageList) => new Promise((resolve, reject) => {
try {
const commands = [imageList[0]];
for (let i = 1; i < imageList.length; i += 1) {
commands.push('-coalesce', 'null:', imageList[i], '-layers', 'composite');
}
commands.push(`${rootPath}/images/${imageName}.png`);
imagemagick.convert(commands, (error, result) => {
if (error) {
console.error(error);
reject(error);
} else {
console.log(result);
resolve(`${rootPath}/images/${imageName}.png`);
}
});
} catch (error) {
reject(error);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment