我需要写一个Python程序来加载PSD photoshop图像,它有多个层,吐出png文件(每层一个)。你能用Python做到这一点吗?我尝试过PIL,但似乎没有任何访问层的方法。帮助。PS。编写我自己的PSD加载器和png编写器已经显示出太慢了。
发布于 2011-07-20 17:23:29
使用Gimp-Python?http://www.gimp.org/docs/python/index.html
你不需要那样的Photoshop,它应该可以在任何运行Gimp和Python的平台上工作。这是一个很大的依赖,但却是免费的。
对于在PIL中执行此操作:
from PIL import Image, ImageSequence
im = Image.open("spam.psd")
layers = [frame.copy() for frame in ImageSequence.Iterator(im)]编辑: OK,找到解决方案:https://github.com/jerem/psdparse
这将允许你使用python从psd文件中提取层,而不需要任何非python的东西。
发布于 2019-06-13 15:37:46
在Python中使用psd_tools
from psd_tools import PSDImage
psd_name = "your_name"
x = 0
psd = PSDImage.open('your_file.psd')
for layer in psd:
x+=1
if layer.kind == "smartobject":
image.conmpose().save(psd_name + str(x) + "png")发布于 2012-04-04 10:36:28
使用python的win32com插件(可以在这里找到:http://python.net/crew/mhammond/win32/),你可以访问photoshop,轻松地浏览你的图层并导出它们。
下面是一个代码示例,它处理当前活动的Photoshop文档中的图层,并将它们导出到'save_location‘中定义的文件夹中。
from win32com.client.dynamic import Dispatch
#Save location
save_location = 'c:\\temp\\'
#call photoshop
psApp = Dispatch('Photoshop.Application')
options = Dispatch('Photoshop.ExportOptionsSaveForWeb')
options.Format = 13 # PNG
options.PNG8 = False # Sets it to PNG-24 bit
doc = psApp.activeDocument
#Hide the layers so that they don't get in the way when exporting
for layer in doc.layers:
layer.Visible = False
#Now go through one at a time and export each layer
for layer in doc.layers:
#build the filename
savefile = save_location + layer.name + '.png'
print 'Exporting', savefile
#Set the current layer to be visible
layer.visible = True
#Export the layer
doc.Export(ExportIn=savefile, ExportAs=2, Options=options)
#Set the layer to be invisible to make way for the next one
layer.visible = Falsehttps://stackoverflow.com/questions/6759459
复制相似问题