As seen from an article, PIL 1.1.5 has built-in Gaussian blur, but is not mentioned in the document, and PIL Gaussian blur in the radius is hard-coded, although the construction method has the incoming radius parameters, but there is no use (see here), so need to transform themselves, of course, Knowing the reason, it's naturally very easy to change.
In combination with the requirements in the post, Gaussian Blur is performed locally, so it is also necessary to use the crop and paste methods to implement the local filter.
The code is as follows:
#-*-coding:utf-8-*-from PIL import Image, Imagefilterclass 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) bounds = ( 280, () image = Image.open (' source.jpg ') image = Image.filter (Mygaussianblur (radius=29, Bounds=bounds)) Image.show ()
You can look at the effect: