gm
gm copied to clipboard
question: how to nest commands?
hi!
I am able to flatten pictures, like this:
convert img1.png img2.png img3.png -flatten out.png
with this js code:
gm().command("convert").in("img1.png").in("img2.png").in("img3.png").in("-flatten").toBuffer('PNG' ...
but now I want to tint one of the images, like this:
convert img1.png \( img2.png -fill green -colorize 50% \) img3.png -flatten out.png
but I had not succeed, I tried: ```
.in("(img2.png -fill green -colorize 50% )") .in("\(img2.png -fill green -colorize 50% \)")
what is the proper way to pass nested commands? thanks!
i do have the same issue, i cant get nested commands to work.
example command i want to get working is:
convert background.png ( overlay.png -resize 50x50 -virtual-pixel None +distort SRT 0,0,1,45,0,0 -repage "+200+40^!" ) -compose Over -layers merge out.png
any tips?
Found similar on #520 This is how I did it...
gm(fs.readFileSync(path))
.command("convert")
.out("(")
.out("-clone", "0")
.out("-background", "black")
.out("-shadow", "80x3+10+10")
.out(")")
.out("(")
.out("-clone", "0")
.out("-background", "white")
.out("-shadow", "80x3+-5-5")
.out(")")
.out("-reverse")
.out("-background", "none")
.out("-layers", "merge")
.out("+repage")
.toBuffer('PNG', function(err, buffer) {
console.log('test-gm', err, buffer);
if(!err) {
fs.writeFileSync(outPath, buffer);
console.log('Written', outPath);
}
});
Hello, thank you for showing your work. It helped me a lot to understand the commands. I wrote a converter that generates GM's chain of operators dynamically by parsing the convert
command. So, we don't need to write NodeJs for every different convert
query. It may be helpful to you, check it out here: https://stackoverflow.com/a/71910087/3963197