Related resources
In our recent project we came across a need for a script that will blur out part of an image. This feature is mostly needed to make people faces blurred out - but also to remove any personal data, like licence plate numbers, etc. We wanted our users to have a smudge tool that would works exactly like in Photoshop, but in their browser. Unfortunately, as it turns out, it is way too much to ask for from Java Script, and even if we would succeed in adding such a feature, it would most likely work really slowly.
At this moment we were left with two options use Adobe Flash or Java Script with PHP.
And as we try to avoid Flash as much as possible, we went for the second one.
Our solution is pretty simple we are using ImageMagick that is being executed by PHP. The blurring itself takes place on the server, but full control of it is through browser. On the client side we have Java Script that allows user to select region that he wants to blur out, and then when user confirms by clicking on a link an AJAX message is sent to the PHP script, containing coordinates of user's selection.
On the browser side we used jQuery with a very nice plugin called imgAreaSelect that allows user to select rectangle-shaped area of image for bluring out. It took us a while to find the blur command for ImageMagick that would blur out only part of the image.
Here is the code for blurring:
Another way to make some part of an image less recognisable is to pixelate it, you can use following command for that:
Of course you should change inputImage, outputImage filenames and coordinates (x1,x2,y1,y2) to match your requirements. In our example coordinates are passed through GET by AJAX query. The full PHP part of the script should look like following:
The JavaScript takes care of retrieving coordinate values from imgAreaSelect and sending them to our PHP script by AJAX, so for person using it, it appears as images is transformed on their own machine. Using a callback function we replace presented image with a newly transformed one once PHP is finished with its job.
Useful links
- Have a look at the demo > blur example
- You can also download a tarball containing the example







Comments
There are no comments for this post