最近无聊,玩一玩python
我的环境是py3
依赖包PIL
关于PIL的安装问题可以看我的另一篇文字。
废话多了
直接上代码
from PIL import Image, ImageFilter, ImageOps
img = Image.open(‘D:\xl\lp2.jpg’)
def dodge(a, b, alpan):
return min(int(a * 255 / (255 - b * alpan)), 255)
def draw(img, blur=25, alpan=1.0):
img1 = img.convert(‘L’)
img2 = img1.copy()
img2 = ImageOps.invert(img2)
for i in range(blur):
img2 = img2.filter(ImageFilter.BLUR)
width, height = img1.size
for x in range(width):
for y in range(height):
a = img1.getpixel((x, y))
b = img2.getpixel((x, y))
img1.putpixel((x, y), dodge(a, b, alpan))
img1.show()
img1.save(‘D:\xl\lp3.png’)
draw(img)
转载:https://blog.csdn.net/u010757530/article/details/106069151
查看评论