将图像文件作为图层加载到 Photoshop
Loading image file as a layer to Photoshop
我有一个包含两个图像的现有 PSD 文件。我的目标是将其中一张图片更改为位于同一文件夹中的另一张图片。我检查了其他问题并发现 Python 可以通过不同的方式实现相同的结果,但是我找不到我想要的实现的解决方案。 (我想通过 Photoshop 的 COM 接口来实现)
实际上,我可以访问图层并设置它们的属性,但无法更改源 image/object。
import win32com.client
import os
# opens ps
psApp = win32com.client.Dispatch("Photoshop.Application")
# opens file
psApp.Open(r"F:\dev\ae\f1.psd")
# new image to add
img1 = r"F:\dev\ae\img1.png"
doc = psApp.Application.ActiveDocument
# new blank layer
doc.ArtLayers.Add()
# get layer to change
layer = doc.ArtLayers[1]
Adobe has scripting guides for various languages and I figured out that most of the method and property names in Python are based on the VBScript version
, but I couldn't figure out the solution even with the docs。当我在 ArtLayers
上调用 Add()
方法时,它会创建一个空白层,但我没有找到另一种方法来对 image/smartobject.
执行相同的操作
嘿,我一直在寻找同样的东西,在你找到的文档中挖掘示例代码后,这就是我找到的解决方法。
psApp.Load(img1)
psApp.ActiveDocument.Selection.SelectAll()
psApp.ActiveDocument.Selection.Copy()
psApp.ActiveDocument.Close()
psApp.ActiveDocument.Paste()
我的意思是它有点愚蠢,但它确实有效。如果不是最后一个,您可能需要 re-select 粘贴之前所在的文档。
我有一个包含两个图像的现有 PSD 文件。我的目标是将其中一张图片更改为位于同一文件夹中的另一张图片。我检查了其他问题并发现 Python 可以通过不同的方式实现相同的结果,但是我找不到我想要的实现的解决方案。 (我想通过 Photoshop 的 COM 接口来实现)
实际上,我可以访问图层并设置它们的属性,但无法更改源 image/object。
import win32com.client
import os
# opens ps
psApp = win32com.client.Dispatch("Photoshop.Application")
# opens file
psApp.Open(r"F:\dev\ae\f1.psd")
# new image to add
img1 = r"F:\dev\ae\img1.png"
doc = psApp.Application.ActiveDocument
# new blank layer
doc.ArtLayers.Add()
# get layer to change
layer = doc.ArtLayers[1]
Adobe has scripting guides for various languages and I figured out that most of the method and property names in Python are based on the VBScript version
, but I couldn't figure out the solution even with the docs。当我在 ArtLayers
上调用 Add()
方法时,它会创建一个空白层,但我没有找到另一种方法来对 image/smartobject.
嘿,我一直在寻找同样的东西,在你找到的文档中挖掘示例代码后,这就是我找到的解决方法。
psApp.Load(img1)
psApp.ActiveDocument.Selection.SelectAll()
psApp.ActiveDocument.Selection.Copy()
psApp.ActiveDocument.Close()
psApp.ActiveDocument.Paste()
我的意思是它有点愚蠢,但它确实有效。如果不是最后一个,您可能需要 re-select 粘贴之前所在的文档。