使用 Image.filter(ImageFilter.BLUR) 方法模糊图像时出现问题。
我的代码:
#Open the image from the ImageField
fp_big = open(self.image_big.path, 'rb')
im_big = Image.open(StringIO(fp_big.read()))
#Resize the image
im_big.thumbnail(size_big, Image.ANTIALIAS)
#Blur the image
im_big = im_big.convert('RGB')
for i in range(10):
im_big = im_big.filter(ImageFilter.BLUR)
#Save the images
temp_handle_big = StringIO()
im_big.save(temp_handle_big, PIL_TYPE)
temp_handle_big.seek(0)
#Save image to a SimpleUploadedFile which can be saved into ImageField
suf_big = SimpleUploadedFile('%s' % os.path.split(self.image_big.name)[-1], temp_handle_big.read(), content_type=IMG_TYPE)
#Delete old images and close fps
fp_big.close()
os.remove(original_path_big)
虽然此代码工作正常,但结果部分错误:
如您所见,图像的边缘没有正确模糊。有谁知道为什么会这样?
提前谢谢。