0

I have this function:

async function convertImage(sentenceIndex){ return new Promise((resolve, reject) => { const inputFile = ./content/${sentenceIndex}-original.png[0] const outputFile = ./content/${sentenceIndex}-converted.png const width = 1920 const height = 1080

        gm()
            .in(inputFile)
            .out('(')
                .out('-clone')
                .out('0')
                .out('-background', 'white')
                .out('-blur', '0x9')
                .out('-resize', `${width}x${height}^`)
            .out(')')
            .out('(')
                .out('-clone')
                .out('0')
                .out('-background', 'white')
                .out('-resize', `${width}x${height}`)
            .out(')')
            .out('-delete', '0')
            .out('-gravity', 'center')
            .out('-compose', 'over')
            .out('-composite')
            .out('-extent', `${width}x${height}`)
            .write(outputFile, (error) => {
                if(error){
                    return reject(error)
                }

                console.log(`> Image converted: ${inputFile}`)
                resolve()
            })
    })
}

Its suposed to build this image (https://i.ibb.co/R2nxryp/imageupload.png);

Im running it on ubuntu but it keep saying that that the file could not be found. Its just a ranom error, as long as if i remove the out commands it runs well.

"(node:30522) UnhandledPromiseRejectionWarning: Error: Command failed: convert convert: Unable to open file (() [No such file or directory]."

The path isnt the problem.

Already changed it to: const inputFile = path.resolve(rootPath, '..', 'html/conteudo', ${sentenceIndex}-original.png) const outputFile = path.resolve(rootPath, '..', 'html/conteudo', ${sentenceIndex}-converted.png)

But same error. Can anyone help me? Thanks in advance!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.