python 去除图片水印

from itertools import product
from PIL import Image

def Remove_watermark(fileName):
    img1 = Image.open(fileName)
    # img1如果不是RGB模式,需要转成RGB模式
    print(img1.mode)
    img = img1.convert('RGB')
    print(img.mode)
    width, height = img.size
    for pos in product(range(width), range(height)):
        #600是经验值,需要根据实际情况调整
        if sum(img.getpixel(pos)[:3]) > 600:
            img.putpixel(pos, (255, 255, 255))
    img.save(fileName)

 

posted on 2022-04-24 17:39  shaomine  阅读(382)  评论(0编辑  收藏  举报