- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我似乎无法让 Node 理解我的 Imagemagick 转换命令。它在终端中运行良好,我已经尝试了大量不同的转义字符排列,但它仍然读取我的 args 数组中的每个单独的字符串值,以尝试转换图像:
转换\
输入.jpg\
-写入mpr:XY\
+删除\
-尊重括号\
\( mpr:XY -resize x640 -采样因子 4:2:0 -strip -interlace Plane +write output-640.jpg\)\
\( mpr:XY -resize x320 -采样因子 4:2:0 -strip -interlace Plane +write output-320.jpg\)\
\( mpr:XY -resize x155 -采样因子 4:2:0 -strip -interlace Plane +write output-155.jpg\)\
\( mpr:XY -调整大小 x45 -采样因子 4:2:0 -strip -交错平面 +写入输出-45.jpg\)\
空:
这在 shell 中运行得很好。然而,这段代码完全失败了
// const spawn = require('child-process-promise').spawn;
var spawn = require('child_process').spawn;
function argsForSize(number) {
return [
'\\(',
'mpr:XY',
'-resize',
'x' + number,
'-sampling-factor',
'4:2:0',
'-strip',
'-interlace',
'Plane',
'+write',
'output-' + number +'.jpg',
'\\)\\'
]
}
let inputPath = '/Users/xconanm/Desktop/imagemagick/test-app/input.jpg';
var args = [
inputPath, '\\',
'-write', 'mpr:XY', '\\', // resize width to 640
'+delete', '\\',
'-respect-parentheses', '\\'
];
let extraArgs = argsForSize(640).concat(argsForSize(320)).concat(argsForSize(155)).concat(argsForSize(55));
extraArgs.push('null:');
args = args.concat(extraArgs)
let child = spawn('convert', args)
console.log(args);
child.stdout.on('data', function(data) {
console.log('stdout: ' + data);
//Here is where the output goes
});
child.stderr.on('data', function(data) {
console.log('stderr: ' + data);
//Here is where the error output goes
});
child.on('close', function(code) {
console.log('closing code: ' + code);
//Here you can get the exit code of the script
});
最佳答案
明白了......可能效率低下,但是:耸肩
// const spawn = require('child-process-promise').spawn;
var spawn = require('child_process').spawn;
function argsForSize(number) {
return [
'-write',
'mpr:XY',
'+delete',
'-respect-parentheses',
'mpr:XY',
'-resize',
'x' + number,
'-sampling-factor',
'4:2:0',
'-strip',
'-interlace',
'Plane',
'-write',
'output-' + number +'.jpg'
]
}
let inputPath = '/Users/xconanm/Desktop/imagemagick/test-app/input.jpg';
var args = [
inputPath
];
let extraArgs = argsForSize(640).concat(argsForSize(320)).concat(argsForSize(155)).concat(argsForSize(55));
extraArgs.push('null:');
args = args.concat(extraArgs)
let child = spawn('convert', args)
console.log(args);
child.stdout.on('data', function(data) {
console.log('stdout: ' + data);
//Here is where the output goes
});
child.stderr.on('data', function(data) {
console.log('stderr: ' + data);
//Here is where the error output goes
});
child.on('close', function(code) {
console.log('closing code: ' + code);
//Here you can get the exit code of the script
process.exit();
});
关于node.js - Imagemagick/Shell/子进程 NodeJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52354848/
需要帮助将这些给定的数字打印成星号,但我是编程新手;我该怎么做? #include int main(void) { int a[5]={20,1,5,15,12}; int i=0
使用 Delphi XE 2 我试图确定缩放方向以将缩放效果应用于图像(TImage),但没有找到执行此操作的函数,并且图像的 OnGesture 事件中的 EventInfo 属性没有此信息. 我见
我不知道制服在内存中是如何表示的。 制服似乎会占用宝贵的寄存器空间,但它们最终会传入/通过/传出到全局内存中,对吗? 制服不用时情况会发生变化吗?编译器可以将它们优化掉吗?--在这种情况下,我已经将无
我正在尝试在名为“timeclock”的模型上记录“time_in”和“time_out”记录。这是我想做但无法开始工作的事情! 检查最后一个时钟条目,看看它是否同时填充了“time_in”和“tim
我想听听您如何解决这种编程任务!?每种类型(OPER = 1 类型)对应一种特定的信息。 这只是大约 10 个具有相同结构的规范之一。首选创建这些“转换器”(协议(protocol))的通用方法。 最
我正在使用 Rest API(NodeJS、Express)和 PostgreSQL 制作 React-Native 应用。 在我的本地机器上托管时一切正常。当 API 托管在我的机器上并且 Post
我是一名优秀的程序员,十分优秀!