我正在尝试使图像的一部分变得模糊。最终我想模糊脸部,但我不能只模糊一部分。我正在尝试裁剪图像的一部分,然后将其粘贴回原始图像。我可以裁剪它,但是当我去保存粘贴裁剪区域的图像时,我收到一个“AttributeError:‘NoneType’对象没有属性‘save’”
这是我使用的代码:
import Image, ImageFilter
picture = Image.open("picture1.jpg")
#finds width and height of picture
width, height = picture.size
#crops the picture
box = (20, 20, width/2, height/2)
ic = picture.crop(box)
#blurs the cropped part of the picture
ic = ic.filter(ImageFilter.GaussianBlur(radius=20))
#pastes the image back
blurredPic = picture.paste(ic, box)
#saves the new image and the cropped image
blurredPic.save("BlurredPic.jpg")
ic.save("cropPic.jpg")
非常感谢您的帮助。
最佳答案
picture.paste(ic, box)
就地改变 picture
并返回 None
。
即。
#blurs the cropped part of the picture
ic = ic.filter(ImageFilter.GaussianBlur(radius=20))
#pastes the image back
picture.paste(ic, box)
#saves the new image and the cropped image
picture.save("BlurredPic.jpg")
ic.save("cropPic.jpg")
关于Python 属性错误 : 'NoneType' object has no attribute 'save' when trying to save a cropped image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19508074/