尧图网站建设 尧图网络
  • 首页
  • 关于我们
  • 服务项目
  • 案例展示
  • 建站流程
  • 资讯中心
  • 联系我们
首页/资讯中心/详情

使用python脚本大批量自动化处理图片上的ai水印

使用python脚本大批量自动化处理图片上的ai水印
📅 发布时间:2026/6/19 18:17:24
import os
import time
from pywinauto.application import Application
from pywinauto.keyboard import send_keys
import traceback
from pywinauto import  mousedef get_app_and_main_window(app_path):app = Application(backend="uia").start(app_path)# app = Application(backend="uia").connect(path=app_path)# 等待应用程序加载time.sleep(1)# 获取主窗口main_window = app.window(title_re=".*Inpaint.*", control_type='Window')# main_window.print_control_identifiers()main_window.wait('visible', timeout=10)print("已连接到应用程序主窗口")return app, main_windowdef open_file_with_ctrl_o(app, file_path):"""使用 Ctrl+O 快捷键打开文件对话框并选择文件参数:app_path: 应用程序路径file_path: 要打开的文件路径"""try:# 激活窗口确保接收键盘输入main_window = app.top_window()main_window.set_focus()# # 使用 Ctrl+O 打开文件对话框# # 常用的控制快捷键说明 # SHIFT +,CTRL ^,ALT %,空格键 {SPACE},BACKSPACE {BACKSPACE}、# {BS} or {BKSP},BREAK {BREAK},CAPS LOCK {CAPSLOCK},# DEL or DELETE {DELETE} or {DEL},DOWN ARROW {DOWN},# END {END},ENTER {ENTER} or ~,ESC {ESC},HELP {HELP},# HOME {HOME},INS or INSERT {INSERT} or {INS},LEFT ARROW {LEFT},# NUM LOCK {NUMLOCK},PAGE DOWN {PGDN},# PAGE UP {PGUP},PRINT SCREEN {PRTSC},# RIGHT ARROW {RIGHT},SCROLL LOCK {SCROLLLOCK},# TAB {TAB},UP ARROW {UP},+ {ADD},- {SUBTRACT},# * {MULTIPLY},/ {DIVIDE},send_keys('^o')  # ^ 代表 Ctrl 键print("已发送 Ctrl+O 打开文件对话框")# # 打印所有控件信息# # main_window.print_control_identifiers()# # 打开文件对话框,并点击打开main_window.child_window(title="文件名(N):", class_name="Edit").set_text(file_path)main_window.child_window(title="打开(O)", class_name="Button").click()print("已确认文件选择并打开")time.sleep(1)# 移动鼠标,左上角水印位置left_top_watermark_position = (742, 125)# 移动鼠标,右下角水印位置right_down_top_watermark_position = (824, 125)mouse.move(coords=left_top_watermark_position)# 指定位置,鼠标左击mouse.click(button='left', coords=left_top_watermark_position)# 将属性移动到(140,40)坐标处按下mouse.press(button='left', coords=left_top_watermark_position)# 将鼠标移动到(300,40)坐标处释放,mouse.release(button='left', coords=right_down_top_watermark_position)# 移动鼠标,左上角水印位置left_top_watermark_position_2 = (1133, 970)# 移动鼠标,右下角水印位置right_down_top_watermark_position_2 = (1250, 1000)mouse.move(coords=left_top_watermark_position_2)# 指定位置,鼠标左击mouse.click(button='left', coords=left_top_watermark_position_2)# 将属性移动到(140,40)坐标处按下mouse.press(button='left', coords=left_top_watermark_position_2)# 将鼠标移动到(300,40)坐标处释放,mouse.release(button='left', coords=right_down_top_watermark_position_2)print("水印区域框选完成")top_window=app.top_window()# top_window.print_control_identifiers()# 点击处理图像chuli_window=top_window.child_window(title="处理图像", control_type="Button")chuli_window.click()time.sleep(10)#  保存send_keys('^s')  # ^ 代表 Ctrl 键print("已发送 Ctrl+s 保存文件对话框")# 另存为# top_window.child_window(title="另存为", control_type="Button").click() #这里执行click后,程序会阻塞,暂时忽略# top_window_2=app.top_window()# top_window_2.print_control_identifiers()## # # 打开文件对话框,并点击打开# top_window_2.set_focus()# top_window_2.child_window(title="文件名(N):", class_name="Edit").set_text(out_file_path)# top_window_2.child_window(title="保存(S)", class_name="Button").click()return Trueexcept Exception as e:# print(f"操作过程中出现错误: {e}")traceback.print_exc()return Falsedef batch_replace_image(app,main_window,file_path):try:for i in os.listdir(file_path):if i.endswith('.png') or i.endswith('.jpg'):image_path = os.path.join(file_path, i)open_file_with_ctrl_o(app,image_path)# print(i)except Exception as e:# print(f"操作过程中出现错误: {e}")traceback.print_exc()return Falsedef app_kill(app):try:app.kill()print("已关闭应用程序")except Exception as e:print(f"关闭应用程序时出现错误: {e}")# 使用示例
if __name__ == "__main__":inpaint_path = r'D:\exe安装包\Inpaint_v9.1_x64.exe'file_path = r'E:\AI生成\AI绘本\10月15日'app, main_window = get_app_and_main_window(inpaint_path)batch_replace_image(app,main_window,file_path)app_kill(app)

有问题可以随时反馈

脑子不够用当然只能脚踏实地的做事情!

相关新闻

  • springboot结合阿里巴巴easyexcel,实现一键导出数据到Excel中
  • 深入解析:PX4 无人机地面调试全攻略:从机械到参数的系统优化
  • 2025年陶瓷过滤板厂家推荐排行榜,白刚玉陶瓷过滤板,棕刚玉陶瓷过滤板,扇形陶瓷板,真空陶瓷过滤板,陶瓷滤膜,陶瓷过滤机配件公司推荐

最新新闻

  • 2026苏州钻石回收实测|国标4C定级,全城无套路靠谱门店变现指南 - 薛定谔的梨花猫
  • C语言宽字符处理:wmemcmp、wmemcpy、wprintf核心函数详解与实战
  • 多模态大语言模型LISA
  • 2026长沙回收百达翡丽手表门店分级指南,一线标杆店铺评级,区分正规与小作坊 - 名奢变现站
  • 如何通过WeChatMsg实现微信聊天记录的本地化解析与数据主权保护?
  • 告别GUI开发噩梦:用Dear ImGui在30分钟内为C++项目添加专业界面

日新闻

  • 5分钟掌握Python进化算法:Geatpy高性能优化工具完全指南
  • Microchip 24AA044 EEPROM选型与应用全指南:从参数解析到实战编程
  • 华为的鸿蒙到底有多牛?为什么称作遥遥领先?

周新闻

  • 3步解锁iOS设备:applera1n激活锁绕过完全指南
  • 39 2026 人工智能证书终极盘点,普通人选 AI 证书可以从这些方向入手
  • Redis 暴露公网有多危险?从端口检查到补救步骤

月新闻

  • 【总结】入门篇:50句话让你记住架构核心概念
  • WeChatMsg技术方案解析:实现Mac微信数据自主管理的完整解决方案
  • WeChatMsg:革新性微信数据备份方案,打造你的专属数字记忆库

关于尧图

  • 公司简介
  • 团队介绍
  • 企业文化
  • 荣誉资质

服务项目

  • 定制开发
  • 电商建站
  • UI 设计
  • 运维服务

快速链接

  • 案例展示
  • 建站流程
  • 常见问题
  • 资讯中心

联系方式

  • 📍北京市朝阳区互联网产业园 A 座 10 层
  • 📞400-888-8888
  • ✉️contact@rkmt.cn
  • 🕐周一至周日 9:00-21:00

© 2024 北京尧图网络科技有限公司 版权所有 | 京 ICP 备 XXXXXXXX 号