首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python PSD层?

Python PSD层?
EN

Stack Overflow用户
提问于 2011-07-20 17:06:59
回答 4查看 13.6K关注 0票数 6

我需要写一个Python程序来加载PSD photoshop图像,它有多个层,吐出png文件(每层一个)。你能用Python做到这一点吗?我尝试过PIL,但似乎没有任何访问层的方法。帮助。PS。编写我自己的PSD加载器和png编写器已经显示出太慢了。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-07-20 17:23:29

使用Gimp-Python?http://www.gimp.org/docs/python/index.html

你不需要那样的Photoshop,它应该可以在任何运行Gimp和Python的平台上工作。这是一个很大的依赖,但却是免费的。

对于在PIL中执行此操作:

代码语言:javascript
复制
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的东西。

票数 5
EN

Stack Overflow用户

发布于 2019-06-13 15:37:46

在Python中使用psd_tools

代码语言:javascript
复制
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")
票数 2
EN

Stack Overflow用户

发布于 2012-04-04 10:36:28

使用python的win32com插件(可以在这里找到:http://python.net/crew/mhammond/win32/),你可以访问photoshop,轻松地浏览你的图层并导出它们。

下面是一个代码示例,它处理当前活动的Photoshop文档中的图层,并将它们导出到'save_location‘中定义的文件夹中。

代码语言:javascript
复制
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 = False
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6759459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档