I. Installation of PIL
PIL is short for Python Imaging Library, which is used to process images.PIL already has a class for Gaussian blur processing of images, but there is a bug (the latest 1.1.7 bug still exists), which is that the blur radius is written to be 2, and cannot be set. It's in line 160 of the source code:
So, we'll just change it ourselves here and it'll be OK.
Project Address:/products/pil/
II. Modified code
The code is as follows:
#-*- coding: utf-8 -*-
from PIL import Image, ImageFilter
class MyGaussianBlur():
name = "GaussianBlur"
def __init__(self, radius=2, bounds=None):
= radius
= bounds
def filter(self, image):
if :
clips = ().gaussian_blur()
(clips, )
return image
else:
return image.gaussian_blur()
III. Calls
simg = ''
dimg = 'demo_blur.jpg'
image = (simg)
image = (MyGaussianBlur(radius=30))
(dimg)
print dimg, 'success'
If you only need to process a certain area, just pass in the bounds parameter
IV. Effects
Original image:
Processed: