Working on part of an image

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
Pacio

Working on part of an image

Post by Pacio »

Hey,

What I would like to achieve:
There is some image with a person. I click on the face and JavaScript sends (x,y) coordinates to PHP so Imagick can create a circle (x,y) with radius=25px. The point is that I wand that circle to be a blur filter, so the face can't be recognised after all.

My question - Is it possible to blur just a part of image, in that case a circle with known radius and coordinates?

Regards
Pacio
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Working on part of an image

Post by el_supremo »

You can't just say "blur this circle" but you can do what you want with a small amount of computation.
But first, do you really need a circular area? Can you make do with a square? It is much easier to do this with a square rather than a circle.
I don't know how to do this with PHP but, if you can make do with a square, basically the process would be to crop the square out of the original image, blur it and then composite it back over the original.
If you insist on a circle it's a bit more complicated. First you extract the square and blur it as before, but then you have to make a circular mask (a white circle on a black background) and use the copyopacity composite operation to make this the alpha channel of the face image. Then composite this over the original.
BTW the reason for cropping the square and then blurring it is that the blur operation is quite slow. So it is faster to blur the cropped area and then put it back rather than blur the whole image.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Working on part of an image

Post by magick »

ImageMagick supports masks that can be used to operate on a portion of any image as defined by the mask. See http://www.imagemagick.org/Usage/. Hopefully it includes an example of using masks.
Pacio

Re: Working on part of an image

Post by Pacio »

el_supremo wrote:But first, do you really need a circular area? Can you make do with a square? It is much easier to do this with a square rather than a circle.
I wanted to make it as easy as possible, so the user click once on the face and it creates a circle, but now I thought about it more and I'll probably make it with a square so people can specify more detailed area to cover by the blur filter. Already set radius could lead to leaving some face parts visible, especially with bigger images. And as I see it will be much more easier to copy a part (square) of image, make it blurred and then paste it back into the same place of original image.

Thanks for replies.

Regards
Pacio
Post Reply