Created
September 4, 2022 12:04
-
-
Save 6londe/1b201d59243c3b180696eaa7ecc32847 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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