First, install the PIL
PIL is the Python Imaging library abbreviation for processing pictures. PIL has a Gaussian blur processing class, but there is a bug (the latest 1.1.7bug still exists), that is, the fuzzy radius of the dead is 2, cannot be set. On the 160th line of source imagefilter.py:
So, we can change it here by ourselves OK.
Project Address: http://www.pythonware.com/products/pil/
Second, the revised Code
The code is as follows:
Copy the Code code as follows:
#-*-Coding:utf-8-*-
From PIL import Image, ImageFilter
Class Mygaussianblur (Imagefilter.filter):
Name = "Gaussianblur"
def __init__ (self, radius=2, Bounds=none):
Self.radius = Radius
Self.bounds = Bounds
def filter (self, image):
If Self.bounds:
Clips = Image.crop (self.bounds). Gaussian_blur (Self.radius)
Image.paste (clips, self.bounds)
return image
Else
Return Image.gaussian_blur (Self.radius)
Third, call
Copy the Code code as follows:
simg = ' demo.jpg '
dimg = ' demo_blur.jpg '
Image = Image.open (simg)
Image = Image.filter (Mygaussianblur (radius=30))
Image.Save (DIMG)
Print dimg, ' success '
If you only need to work with an area, pass in the bounds parameter
Four, the effect
Original:
After the treatment: