用python编写一段给图片添加光环滤镜的程序
时间: 2024-04-29 22:26:02 浏览: 10
好的,以下是用Python编写的添加光环滤镜的程序:
```python
from PIL import Image, ImageOps
def add_halo_filter(image_path, halo_color):
'''
给图片添加光环滤镜
:param image_path: 图片路径
:param halo_color: 光环颜色
:return: 添加了光环滤镜的图片
'''
# 打开图片
image = Image.open(image_path)
# 图片加边框
border_size = int(max(image.size) * 0.2)
bordered_image = ImageOps.expand(image, border=border_size, fill=halo_color)
# 使用模糊滤镜模糊边框
blurred_image = bordered_image.filter(ImageFilter.GaussianBlur(radius=border_size))
# 将原始图片覆盖在模糊边框上
final_image = Image.composite(image, blurred_image, image)
return final_image
```
这个程序使用Python的Pillow库,实现了给图片添加光环滤镜的功能。你可以将图片路径和光环颜色作为参数传入函数,并返回添加了光环滤镜的新图片。