from PIL import Image
def remove_watermark(image_path, output_path):
# 打开图像文件
img = Image.open(image_path)
# 获取图像的宽度和高度
width, height = img.size
# 假设水印是一个简单的矩形区域,根据你的实际情况修改这部分代码
watermark_width = 121
watermark_height = 98
# 在图像的右下角定义水印区域
watermark_region = (width - watermark_width, height - watermark_height, width, height)
# 创建一个与水印大小相同的空白图像
watermark = Image.new("RGBA", (watermark_width, watermark_height), (0, 0, 0, 255))
# 将水印覆盖在空白图像上
img.paste(watermark, watermark_region, watermark)
# 保存处理后的图像
img.save(output_path)
if __name__ == "__main__":
# 批量处理多个图像
image_files = ["20230731103245788.webp"]
for image_file in image_files:
input_path = "input/" + image_file
output_path = "output/" + image_file
remove_watermark(input_path, output_path)
文章评论