How to pixelate part of an image using ImageMagick?

I’m trying to understand how to pixelize only part of the image, but so far I haven’t achieved anything.

I am currently following the guide below: http://www.mutinydesign.co.uk/free-scripts/live-photo-blurring-script/

Using the jQuery plugin "imgAreaSelect" so that users can select part of the image from the user interface. Then click "pixelate". Then it makes an ajax call to the pixelate function written in php for imagemagick. The pixelate function is as follows:

<?php $x1 = $_GET['x1']; $y1 = $_GET['y1']; $x2 = $_GET['x2']; $y2 = $_GET['y2']; $inputImage = $_GET['inputImage']; $outputImage = 'output_'.$_GET['inputImage']; exec( "convert {$inputImage} \( +clone -scale 20% -scale 500% \) \ \( +clone -gamma 0 -fill white \ -draw 'rectangle {$x1},{$y1} {$x2},{$y2}' -blur 10x4 \) \ -composite {$outputImage}" ); echo $outputImage; ?> 

This works, but pixels the entire image, not just the selected part. Any ideas or suggestions appreciated. Has anyone been able to achieve something like this?

+4
source share
1 answer

What you need to do is split the image into two variables, duplicating it. Then you crop one image around the desired location. Take a pixel, then flip it back to another image in the same place where it was.

Then print it out.

You will have part of the image with blur, and the rest is clear.

+1
source

All Articles