ChildProcessError for image moderation firebase function

为君一笑 提交于 2021-02-10 06:46:09

问题


I'm trying implement image moderation code to remove adult or violent content as given here: https://github.com/firebase/functions-samples/tree/master/generate-thumbnail

But every time i'm getting this error:

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)

due to this line:

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

And one more help what is best way to moderate video instead of image, i.e. if i want to check if video uploaded is not offensive(adult or violent).

Any help is appreciated.


回答1:


Thanks fmw42 for help, it was silly mistake. Issue in command is with whitespaces only, try avoiding spaces in folder name. Anyway if you have handle command carefully like:

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



回答2:


You have:

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

/tmp/test is there in two places and is just a path. ImageMagick will not like a path without an image file. You already have the input and output files with path as folder/yes.jpg. This is why you get

unable to open image `/tmp/test': No such file or directory

Perhaps you meant

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

or

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

or

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

So it looks like your variable replacement or code with variables is incorrect.

P.S. Do you really want to blur the alpha channel? Using -channel RGBA will do so. If you do not want to blur the alpha channel, then use -channel RGB. You may also get a different result without -channel RGBA.



来源:https://stackoverflow.com/questions/44479085/childprocesserror-for-image-moderation-firebase-function

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