图像审核firebase函数

时间:2017-06-10 23:37:58

标签: firebase imagemagick imagemagick-convert

我正在尝试实施图片审核代码,以删除此处给出的成人或暴力内容:https://github.com/firebase/functions-samples/tree/master/generate-thumbnail

但每次我收到此错误:

ChildProcessError: Command failed: convert /tmp/test folder/yes.jpg -channel RGBA -blur 0x8 /tmp/test folder/yes.jpg
convert: unable to open image `/tmp/test': No such file or directory @ error/blob.c/OpenBlob/2712.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
convert: unable to open image `folder/yes.jpg': No such file or directory @ error/blob.c/OpenBlob/2712.
convert: unable to open image `/tmp/test': No such file or directory @ error/blob.c/OpenBlob/2712.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
convert: no images defined `folder/yes.jpg' @ error/convert.c/ConvertImageCommand/3210.
 `convert /tmp/test folder/yes.jpg -channel RGBA -blur 0x8 /tmp/test folder/yes.jpg` (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:213:5)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

由于这一行:

// Blur the image using ImageMagick.
    return exec(`convert ${tempLocalFile} -channel RGBA -blur 0x8 ${tempLocalFile}`);

还有一个帮助什么是温和视频而不是图像的最佳方式,即如果我想检查上传的视频是否具有攻击性(成人或暴力)。

感谢任何帮助。

2 个答案:

答案 0 :(得分:2)

感谢fmw42的帮助,这是一个愚蠢的错误。命令中的问题仅限于空格,请尝试避免文件夹名称中的空格。无论如何,如果你有谨慎的处理命令:

return exec(`convert "${tempLocalFile}" -channel RGBA -blur 0x8 "${tempLocalFile}"`);

答案 1 :(得分:1)

你有:

  

convert / tmp / test folder / yes.jpg -channel RGBA -blur 0x8 / tmp / test folder / yes.jpg

/ tmp / test有两个地方,只是一个路径。 ImageMagick不喜欢没有图像文件的路径。您已经将输入和输出文件的路径作为文件夹/ yes.jpg。这就是你得到的原因

  

无法打开图像`/ tmp / test':没有这样的文件或目录

也许你的意思是

convert /tmp/test/folder/yes.jpg -channel RGBA -blur 0x8 /tmp/test/folder/yes.jpg

convert /tmp/test/yes.jpg -channel RGBA -blur 0x8 /tmp/test/yes.jpg

convert folder/yes.jpg -channel RGBA -blur 0x8 folder/yes.jpg

所以看起来你的变量替换或带变量的代码是不正确的。

P.S。你真的想模糊alpha通道吗?使用-channel RGBA会这样做。如果您不想模糊Alpha通道,请使用-channel RGB。如果没有-channel RGBA,您也可能会得到不同的结果。