Passing 2 stdin arguments to a ImageMagick child_process

ぐ巨炮叔叔 提交于 2019-12-06 03:19:55

As Mark Setchell pointed out in the comments, using ImageMagick's fd: protocol will work.

var spawnOptions = {
      stdio: [
        0, // stdin,
        1, // stdout
        2, // stderr
        'pipe', // arrowBuffer1
        'pipe'  // arrowBuffer2
      ]
};
magic = spawn("convert", magicCommands, spawnOptions);

This opens fd:3 & fd:4 for piping. I'm not failure with the family, but there usually a way to pass a resource in addition to .

For your code

Update the magickCommands variable to read from new fd's, and write directly to new pipes

magicCommands = ["fd:3",
                 "fd:4",
                 "+append",
                 "out.jpg"];

// ...
imagic.stdio[3].write(arrowBuffer1);
imagic.stdio[4].write(arrowBuffer2);
imagic.stdio[3].end();
imagic.stdio[4].end();

Not really sure what these "limitations" are, or what we are trying to avoid or work around, but the following technique of streaming multiple files into one may help you:

# Make a red block
convert -size 50x50 xc:red multi.miff

# Make a green block, but APPEND INTO A SINGLE STREAM
convert -size 50x50 xc:lime miff:- >> multi.miff

# Make a blue block, but APPEND INTO A SINGLE STREAM
convert -size 50x50 xc:blue miff:- >> multi.miff

# Tell IM to convert and append multiple images in single stream 
convert multi.miff +append result.png

Also, if you change the last command above to the following, IM will delete the file multi.miff as soon as it has finished with it - i.e. tidy up for you!

convert ephemeral:multi.miff +append result.png
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!