7

What convert command do I use to blur part of an image. For now I am using

convert source.jpg -fill white  -draw "polyline 671,395 665,356 812,331 818,370"  result.jpg

It creates white four points shape on the image, but I need blur all of this part of the image.

Thanks!

fmw42
  • 46,825
  • 10
  • 62
  • 80
Dima Magunov
  • 163
  • 3
  • 9

2 Answers2

10

In ImageMagick, you can use any mask to limit the blur.

Create a black and white mask image: black inside your quadrilateral and white elsewhere of the size of your image. Then use that as a mask for doing blurring. See http://www.imagemagick.org/Usage/masking/#read_mask.

Input:

enter image description here

(Unix syntax)

convert \
logo.jpg \
\( -clone 0 -fill white -colorize 100 -fill black \
-draw "polygon 332,180 427,105 481,238 399,279" \
-alpha off -write mpr:mask +delete \) \
-mask mpr:mask -blur 0x5 +mask logo_blur.jpg

Blurred Result

enter image description here

fmw42
  • 46,825
  • 10
  • 62
  • 80
  • 2
    It should be mentioned that you can soften the edges of the finished blurred area by blurring the mask, too. Just add "-blur 0x5" before "-write mpr:mask" to get that result. – GeeMack Nov 02 '17 at 04:36
  • 1
    @fmw42 one more question. If I want create several blurred shapes on image, how can I do it with one command? – Dima Magunov Nov 02 '17 at 13:47
  • 1
    Just add another polygon and its coordinates inside the -draw. So `-draw "polygon coordinate_set1 polygon coordinate_set2" – fmw42 Nov 02 '17 at 17:01
  • 1
    As long as you want the same amount of blur on all the shapes, you can simply add more "-draw" operations in the original command, or even create more shapes within the single "-draw" operation like "-draw "polygon 10,10 50,10 50,50 10,10 polygon 80,80 100,80 100,100 80,80" – GeeMack Nov 02 '17 at 17:04
4

Use -region http://www.imagemagick.org/Usage/masking/#region_warping

convert a.png -region 150x150+599+261 -implode 1.5 +region b.png
cancerbero
  • 6,799
  • 1
  • 32
  • 24