当前位置: 首页 > 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.jsqmd.com/news/15278/

相关文章:

  • springboot结合阿里巴巴easyexcel,实现一键导出数据到Excel中
  • 深入解析:PX4 无人机地面调试全攻略:从机械到参数的系统优化
  • 以江协科技STM32入门教程的方式打开FreeRTOS——STM32C8T6如何移植FreeRTOS - 教程
  • 2025年陶瓷过滤板厂家推荐排行榜,白刚玉陶瓷过滤板,棕刚玉陶瓷过滤板,扇形陶瓷板,真空陶瓷过滤板,陶瓷滤膜,陶瓷过滤机配件公司推荐
  • springboot结合阿里巴巴easyexcel,实现一键把Excel数据导入数据库
  • 2025年10月长白山度假酒店推荐:民俗与国际品质兼得
  • 2025年10月长白山度假酒店推荐:民俗与国际范兼得
  • 2025年10月访客系统推荐:五强榜单与选型要点
  • 实习内推】机器人操作系统Dora-rs团队招募实习生(北京)
  • 2025 上海财税服务机构优选榜:上海注册公司与代理记账领域靠谱服务商推荐
  • 实训题
  • GoodSync 2025年10月17日
  • 书本p66实训题第2题
  • 2025全屋定制厂家推荐:聚焦异形空间+特色色系,森佰特木业领衔优质之选
  • springboot 上传图片到服务器之后,前段不能正确加载图片问题
  • springboot 设置文件上传大小
  • 【光照】UnityURP[屏幕空间环境光遮蔽SSAO]原理剖析实践
  • Ai元人文:讨论一种新的决策科学
  • 2025年流量计厂家权威推荐榜单:热式/模拟式/数字式/高压/高温/耐腐蚀/多气体/4-20mA/RS485/分体式/不锈钢高精度流量计公司精选
  • 深入解析:云原生时代的数据流高速公路:深入解剖Apache Pulsar的架构设计哲学
  • DeepResearch代码浅析
  • 2025年连铸机厂家权威推荐榜单:扇形段/大包回转台/钢包中间罐/结晶器总成/拉矫机/引锭杆/输送辊道/液压剪等核心部件专业供应商
  • 机器人控制利器:MPC入门与实践解析 - 指南
  • 2025年10月中国专精特新申报服务机构推荐榜:五强实测
  • 静态初始化块的执行顺序
  • 正态总体中标准化单样本残差的分布推导
  • 2025年轧钢设备厂家权威推荐榜:冷轧机、热轧机源头生产厂家,技术实力与市场口碑深度解析
  • 实用指南:在鸿蒙NEXT中发起HTTP网络请求:从入门到精通
  • 10.16 CSP-S 模拟赛总结
  • 远程无钥匙进入(PKE)技术:便利与安全的完美融合