PhotoShop工具开发之Python(二)
接上篇
前面学会了,怎么打开-关闭 PhotoShop, 今天就来学怎么编辑-导出保存
- 首先连接PhotoShop,学以致用
from comtypes.client import CreateObject
ps_app = CreateObject("Photoshop.Application", dynamic=True)
一.新建图层并填充背景色
- 新建图层
ps_app.Preferences.RulerUnits = 1
new_doc = ps_app.Documents.Add(1024, 1024, 72, "new_doc", 2, 1, 1) #新建文档
new_art_layer = new_doc.ArtLayers.Add()
new_art_layer.name = "background_color_base" # 创建一个名为background_color_base图层
- 设置背景色
background_color = CreateObject('Photoshop.SolidColor')
background_color.rgb.red = 128
background_color.rgb.green = 128
background_color.rgb.blue = 255
- 填充图层
new_doc.selection.Fill(background_color)
二.设置导出TGA选项
tga_options = CreateObject('Photoshop.TargaSaveOptions') # 创建TGA保存选项对象
tga_options.Resolution = 24 # 24位或32位
tga_options.AlphaChannels = False # True 带A通道
tga_options.RLECompression = False #True 压缩方式输出
上面那一堆都是在设置存储选项,可以参照下图TGA另存选项
三.设置保存PSD选项
psd_options = CreateObject('Photoshop.PhotoshopSaveOptions')
psd_options.annotations = False
psd_options.alphaChannels = True
psd_options.layers = True
psd_options.spotColors = True
psd_options.embedColorProfile = True
上面那一堆都是在设置存储选项,可以参照下图PSD另存选项
四.保存
经过上面一顿操作后,我们可以把操作结果保存下来
#保存PSD
new_doc.SaveAs(r"本地路径.psd", psd_options,True)
#保存TGA
new_doc.SaveAs(r"本地路径.tga", tga_options,True)
Ending
目前为止,python操作Photoshop的技巧,已经学会了 打开 - 新建 - 保存 - 退出,下次我们继续深入不同的动作





浙公网安备 33010602011771号