windows python 打开 ps调用动作批量自动化处理本地图片

# This script demonstrates how to use the action manager to execute a
# previously defined action liek the default actions that ships with Photoshop
# Or one that you've created yourself. The name of the action comes from
# Photoshop's Actions Palette
import os

from win32com.client import Dispatch, GetActiveObject, GetObject

def getFileList(dir, Filelist, ext=None):
    """
    获取文件夹及其子文件夹中文件列表
    输入 dir:文件夹根目录
    输入 ext: 扩展名
    返回: 文件路径列表
    """
    newDir = dir
    if os.path.isfile(dir):
        if ext is None:
            Filelist.append(dir)
        else:
            if ext in dir[-3:]:  # jpg为-3/py为-2
                Filelist.append(dir)

    elif os.path.isdir(dir):
        for s in os.listdir(dir):
            newDir = os.path.join(dir, s)
            getFileList(newDir, Filelist, ext)
    return Filelist


org_img_folder = r'C:\\Users\\ZG\\Desktop\\'

# 检索文件
imglist = getFileList(org_img_folder, [], 'jpg')

print('本次执行检索到 ' + str(len(imglist)) + ' 个jpg文件\n')

print(len(imglist))

if len(imglist):
    try:
        app = GetActiveObject("Photoshop.Application")
    except:
        app = Dispatch("Photoshop.Application")

    fileName = "C:\\Users\ZG\\Desktop\\il_fullxfull.2415706261_ez81.jpg"
    docRef = app.Open(fileName)

    for imgpath in imglist:
        imgname = os.path.splitext(os.path.basename(imgpath))[0]
        print(imgpath)
        docRef = app.Open(imgpath)

    app.DoAction('熔化的铅块', '默认动作')





评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值