当前位置: 首页 > news >正文

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

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)

有问题可以随时反馈

http://www.rkmt.cn/news/22873.html

相关文章:

  • springboot结合阿里巴巴easyexcel,实现一键导出数据到Excel中
  • 深入解析:PX4 无人机地面调试全攻略:从机械到参数的系统优化
  • 2025年陶瓷过滤板厂家推荐排行榜,白刚玉陶瓷过滤板,棕刚玉陶瓷过滤板,扇形陶瓷板,真空陶瓷过滤板,陶瓷滤膜,陶瓷过滤机配件公司推荐
  • springboot结合阿里巴巴easyexcel,实现一键把Excel数据导入数据库
  • 2025年工业设备安装厂家权威推荐榜:管道/电气/暖通空调/空压系统/纯水系统/厂房通风/车间配电/机械设备专业安装服务全景解析
  • 实习内推】机器人操作系统Dora-rs团队招募实习生(北京)
  • 机器人控制利器:MPC入门与实践解析 - 指南
  • 2025年轧钢设备厂家权威推荐榜:冷轧机、热轧机源头生产厂家,技术实力与市场口碑深度解析
  • 实用指南:在鸿蒙NEXT中发起HTTP网络请求:从入门到精通
  • string略解
  • 《程序员修炼之道》 阅读笔记二
  • 是时候告别向日葵、Todesk、TeamViewer了,快速搭建自托管服务器RustDesk
  • $\text{Catalan}$ 数 卡特兰数
  • 风险评估的流程和各阶段的工作内容
  • 稀疏离散分数阶傅里叶变换的MATLAB实现
  • 2025 年导轨丝杆源头厂家最新推荐榜,技术实力与市场口碑深度解析的优质企业榜单东莞/直线/滚珠/孚雷导轨丝杆厂家推荐
  • far的数据类型
  • WSL+Ubuntu + AI (Claude, SpecKit, iFlow) 常用命令
  • 事件在react中的处理方式?
  • 农经权报表生成小程序介绍
  • Linux 中检测gz压缩文件是否损坏
  • 2025年信息流代运营服务商权威推荐榜:专业投放策略与高转化效果深度解析,助力企业精准营销
  • 权限维持-Windows权限维持
  • 1017
  • 2025 广州人力资源/派遣/外包/劳务外包/人事代理/推荐榜:精典人才创新 5 星领跑,适配招聘 / 测评 / 培训全场景企业需求
  • 2025 年选矿行业 2 号油厂家最新推荐排行榜:环保型 / 新型 / JQ202/101/QX/BK201/323 起泡剂等产品权威筛选,助力企业选对优质供应商
  • 2025 年探伤仪厂商最新推荐榜单:涡流 / 超声波 / 管材 / 焊缝 / 无损探伤仪优质企业权威盘点
  • 2025 年罗茨风机厂家最新推荐排行榜权威发布!深度解析各品牌优势助企业精准选型UNTW无泄漏/BRW水冷式罗茨风机厂家推荐
  • 【树莓派】安装PostgreSQL
  • 【数据结构】数据结构秘籍:如何衡量“查找”的快慢?ASL是关键! - 教程