Python 白底黑字图片去除红色水印
import os
from PIL import Imagedef remove_color(image_path, new_image_path):"""初始化:param image_path: 图片路径:param new_image_path: 新图片路径"""img = Image.open(image_path).convert("RGBA")datas = img.getdata()new_data = []for item in datas:if sum(item[:3]) in range(300, 765):new_data.append((255, 255, 255, 1))else:new_data.append(item)img.putdata(new_data)img.save(new_image_path, "png")if __name__ == '__main__':file_name_path = 'photo/image.png'new_file_name_path = 'photo/new_image.png'remove_color(file_name_path, new_file_name_path)