Reputation: 1230
I have a service from amazon that returns the cordinates of the face from the picture !!
{ "Top" : 0.16105769574642181, "Left" : 0.32451921701431274, "Height" : 0.2788461446762085, "Width" : 0.27764421701431274 }
and I want to blur only the face (or a square) from the image. I am trying ImageMagick, but am not able to make it work!! So, I found a different way to do it, but am unable to put it into code
http://www.imagemagick.org/Usage/masking/#read_mask
If you know any NPM that can help or how to do it with ImageMagick that would be very helpful
Upvotes: 1
Views: 3169
Reputation: 1230
So I found a solution that is pretty simple:
image => url or path ; faceDetails => is the array of faces aws rekognition returned facesDetails.boundinBox is the object you see in the question
let blur = function(image, faceDetails) {
let img = gm(image);
img.size(function(err, value){
if (err) {
console.log(err);
} else {
faceDetails.forEach((faceDetail) => {
const box = faceDetail.BoundingBox,
width = box.Width * value.width,
height = box.Height * value.height,
left = box.Left * value.width,
top = box.Top * value.height;
img.region(width, height, left, top).blur(0, 50);
});
img.write(__dirname + '/archive/resize.jpg', function (err) {
if (!err) {
console.log('done Wrting .....');
}else{
console.error(err);
}
});
}
});
};
Upvotes: 3