在云函数上运行convert命令会返回我无法在本地重现的错误

时间:2017-10-04 15:24:01

标签: imagemagick google-cloud-functions

鉴于此代码: ```

let exec = require('child-process-promise').exec
let magickCommand = `convert -background none -stroke "rgba(139, 184, 232, 1)" -fill "rgba(136, 183, 232, 0.83)" -font /tmp/1057522377634683-priceFont.ttf -pointsize 70 label:"$48" -trim ( +clone -background "rgba(135, 138, 140, 0.59)" -shadow 80x8+8+10 ) +swap -background none -layers merge +repage -rotate 0 -fuzz 10% -trim /tmp/1057522377634683-priceText.png`
exec(magickCommand).then(() => { console.log('finished') })

``` 我可以在我的Windows机器上本地运行匹配版本的convert,就像谷歌云功能一样:ImageMagick-6.8.9-9-Q16-x64-static

当我在函数上运行相同的Imagemagick命令时,我收到以下错误: ```

{ ChildProcessError: Command failed: convert -background none -stroke "rgba(139, 184, 232, 1)" -fill "rgba(136, 183, 232, 0.83)" -font /tmp/1057522377634683-priceFont.ttf -pointsize 90 label:"$48" -trim \( -clone -background "rgba(135, 138, 140, 0.59)" -shadow 80x8+8+10 \) +swap -background none -layers merge +repage -rotate 0 -fuzz 10% -trim /tmp/1057522377634683-priceText.png
convert: image sequence is required `-clone' @ error/convert.c/ConvertImageCommand/967.
 `convert -background none -stroke "rgba(139, 184, 232, 1)" -fill "rgba(136, 183, 232, 0.83)" -font /tmp/1057522377634683-priceFont.ttf -pointsize 90 label:"$48" -trim \( -clone -background "rgba(135, 138, 140, 0.59)" -shadow 80x8+8+10 \) +swap -background none -layers merge +repage -rotate 0 -fuzz 10% -trim /tmp/1057522377634683-priceText.png` (exited with error code 1)
    at callback (/user_code/node_modules/child-process-promise/lib/index.js:33:27)
    at ChildProcess.exithandler (child_process.js:211:5)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:891:16)
    at Socket.<anonymous> (internal/child_process.js:342:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:497:12)
  name: 'ChildProcessError',
  code: 1,
  childProcess: 
   { ChildProcess: { [Function: ChildProcess] super_: [Object] },
     fork: [Function],
     _forkChild: [Function],
     exec: [Function],
     execFile: [Function],
     spawn: [Function],
     spawnSync: [Function: spawnSync],
     execFileSync: [Function: execFileSync],
     execSync: [Function: execSync] },
  stdout: '',
  stderr: 'convert: image sequence is required `-clone\' @ error/convert.c/ConvertImageCommand/967.\n' }

``` 我已尝试使用和不使用命令(在函数环境中,但是命令exec的任何一种方式仍然失败。函数部署需要15到20分钟 - 调试这个非常慢,我在我的智慧结束。我是希望有人在过去碰到这样的事情,并且能够以我的方式看到错误。

本地和Google-cloud-functions中的节点版本为6.11.2

当我在本地运行命令时,我会生成一个透明的.png文件 Google Drive folder with font and output .png file

1 个答案:

答案 0 :(得分:1)

如果我用label替换label:“$ 48”,我会得到同样的错误(在Linux上):(即没有生成任何内容)。给定起始'$',有可能将$ 48解释为某处的变量名并产生空字符串。暂时更换/删除$不难检查。在这种情况下,解决方案是逃避$:\ $(也许)。