photoshop二次开发python_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的技巧,已經學會了 打開 - 新建 - 保存 - 退出,下次我們繼續深入不同的動作
總結
以上是生活随笔為你收集整理的photoshop二次开发python_PhotoShop工具开发之Python(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【OpenCV 例程200篇】208.
- 下一篇: Python 有趣的囚犯问题