I'm trying to write a basic firebase function which blurs images. The code is based mainly on the firebase function samples:
async function blurImage(filePath, bucketName, metadata) {
const tempLocalFile = path.join(os.tmpdir(), filePath);
const tempLocalDir = path.dirname(tempLocalFile);
const bucket = admin.storage().bucket(bucketName);
// Create the temp directory where the storage file will be downloaded.
await mkdirp(tempLocalDir);
// Download file from bucket.
await bucket.file(filePath).download({destination: tempLocalFile});
// Blur the image using ImageMagick.
await spawn('convert', [tempLocalFile, '-channel', 'RGBA', '-blur', '0x8', tempLocalFile]);
// Uploading the Blurred image.
await bucket.upload(tempLocalFile, {
destination: `${BLURRED_FOLDER}/${filePath}`,
metadata: {metadata: metadata}, // Keeping custom metadata.
});
// Clean up the local file
fs.unlinkSync(tempLocalFile);
}
I am trying to test this locally using firebase functions:shell
and a testData.json
file, however keep getting the error:
ChildProcessError: "convert C:\filePath -channel RGBA -blur 0x8 C:\filePath" failed with code 4
Can someone please tell me how to fix this?