如何在节点imagemagick模块转换函数中传递多个参数

时间:2022-05-03 09:00:30

I am using node imagemagick module's convert function When I am using this command through terminal then it is working fine

我正在使用节点imagemagick模块的转换功能当我通过终端使用此命令时它工作正常

convert /home/manish/Downloads/new_images/slim_fit_double_breasted_coat_base.png /home/manish/Desktop/Medium-Vichy-9274-Fabric-Gauloise-058.jpg \( -clone 0 -auto-level \) \( -clone 1 -clone 0 -alpha set -virtual-pixel transparent -compose displace -set option:compose:args -5x-5 -composite \)   fabric2.png

but when I am passing the same command in node module then it is not giving expected result.

但是当我在节点模块中传递相同的命令时,它没有给出预期的结果。

here is my code

这是我的代码

var im = require('imagemagick');


im.convert(['/home/manish/Downloads/new_images/slim_fit_double_breasted_coat_base.png','/home/manish/Desktop/green-flower-lavender-eye-pillow-fabric.jpg', '-clone', '0', '-auto-level','-clone','1','-clone','0','-alpha' , 'set' ,'-virtual-pixel','transparent','-compose','displace','-set','option:compose:args -5x-5 ','-composite','fabricted111.png'],
    function (err, stdout) {
        if (err) throw err;
        console.log('stdout:', stdout);
});

it is giving error at this argument

它在这个论点上给出错误

'-set','option:compose:args -5x-5 ','-composite'

1 个解决方案

#1


2  

Looks like your code is missing image-stack operator \( ... \), so your code does not match the CLI command.

看起来您的代码缺少图像堆栈运算符\(... \),因此您的代码与CLI命令不匹配。

command = ['/home/manish/Downloads/new_images/slim_fit_double_breasted_coat_base.png',
           '/home/manish/Desktop/green-flower-lavender-eye-pillow-fabric.jpg',
           '\\(',          // <--- missing (
           '-clone',
           '0',
           '-auto-level',
           '\\)',          // <--- missing )
           '\\(',          // <--- missing (
           '-clone',
           '1',
           '-clone',
           '0',
           '-alpha',
           'set',
           '-virtual-pixel',
           'transparent',
           '-compose',
           'displace',
           '-set',
           'option:compose:args -5x-5 ',
           '-composite',
           '\\)',          // <--- missing )
           'fabricted111.png'];
im.convert(command,
    function (err, stdout) {
        if (err) throw err;
        console.log('stdout:', stdout);
});

#1


2  

Looks like your code is missing image-stack operator \( ... \), so your code does not match the CLI command.

看起来您的代码缺少图像堆栈运算符\(... \),因此您的代码与CLI命令不匹配。

command = ['/home/manish/Downloads/new_images/slim_fit_double_breasted_coat_base.png',
           '/home/manish/Desktop/green-flower-lavender-eye-pillow-fabric.jpg',
           '\\(',          // <--- missing (
           '-clone',
           '0',
           '-auto-level',
           '\\)',          // <--- missing )
           '\\(',          // <--- missing (
           '-clone',
           '1',
           '-clone',
           '0',
           '-alpha',
           'set',
           '-virtual-pixel',
           'transparent',
           '-compose',
           'displace',
           '-set',
           'option:compose:args -5x-5 ',
           '-composite',
           '\\)',          // <--- missing )
           'fabricted111.png'];
im.convert(command,
    function (err, stdout) {
        if (err) throw err;
        console.log('stdout:', stdout);
});