Skip to content

Instantly share code, notes, and snippets.

@gantrim
Created February 3, 2019 19:22
Show Gist options
  • Save gantrim/6aa480162818e0a9f6108e7d3513d73a to your computer and use it in GitHub Desktop.
Save gantrim/6aa480162818e0a9f6108e7d3513d73a to your computer and use it in GitHub Desktop.
Firebase Part 6 - Blur Image
function blurImage(object, userDocRef) {
const filePath = object.name;
const bucket = gcs.bucket(object.bucket);
const fileName = filePath.split('/').pop();
const tempLocalFile = `/tmp/${fileName}`;
// Download file from bucket.
return bucket.file(filePath)
.download({
destination: tempLocalFile
})
.then(() => {
console.log('Image has been downloaded to', tempLocalFile);
// Blur the image using ImageMagick.
return exec(`convert ${tempLocalFile} -channel RGBA -blur 0x24 ${tempLocalFile}`);
})
.then(() => {
console.log('Image has been blurred');
// Uploading the Blurred image back into the bucket.
return bucket.upload(tempLocalFile, {
destination: filePath
});
})
.then(() => {
console.log('Blurred image has been uploaded to', filePath);
// Indicate that the message has been moderated.
return userDocRef.update({
locked: true
});
})
.then(() => {
console.log('Marked the image as moderated in the database.');
return fs.unlinkSync(tempLocalFile);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment