main2.py 714 B

1234567891011121314151617181920212223242526272829
  1. from PIL import Image, ImageFilter, ImageOps
  2. img = Image.open("小青-帅.jpeg")
  3. def dodge(a, b, alpha):
  4. return min(int(a * 255 / (256 - b * alpha)), 255)
  5. def draw(img, blur=25, alpha=1.0):
  6. # 图片转换成灰色
  7. img1 = img.convert('L')
  8. img2 = img1.copy()
  9. img2 = ImageOps.invert(img2)
  10. # 模糊度
  11. for i in range(blur):
  12. img2 = img2.filter(ImageFilter.BLUR)
  13. width, height = img1.size
  14. for x in range(width):
  15. for y in range(height):
  16. a = img1.getpixel((x, y))
  17. b = img2.getpixel((x, y))
  18. img1.putpixel((x, y), dodge(a, b, alpha))
  19. img1.show()
  20. img1.save('小青-帅-line.jpeg')
  21. if __name__ == "__main__":
  22. draw(img)