Python PSD 图层?
我需要编写一个Python程序来加载PSD Photoshop图像,该图像具有多层并吐出png文件(每层一个)。 你能用 Python 做到这一点吗?我尝试过 PIL,但似乎没有任何访问图层的方法。帮助。 附言。事实证明,编写我自己的 PSD 加载器和 png 编写器太慢了。
I need to write a Python program for loading a PSD photoshop image, which has multiple layers and spit out png files (one for each layer).
Can you do that in Python? I've tried PIL, but there doesn't seem to be any method for accessing layers. Help.
PS. Writing my own PSD loader and png writer has shown to be way too slow.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在 Python 中使用 psd_tools
Use psd_tools in Python
您可以使用 win32com 通过 Python 访问 Photoshop。
您的工作可能的伪代码:
You can use the win32com for accessing the Photoshop with Python.
Possible pseudo code for your work:
使用 python 的 win32com 插件(可在此处获取:http://python.net/crew/mhammond/win32/ )您可以访问 Photoshop 并轻松浏览图层并将其导出。
以下是一个代码示例,适用于当前活动的 Photoshop 文档中的图层,并将它们导出到“save_location”中定义的文件夹中。
Using the win32com plugin for python (available here: http://python.net/crew/mhammond/win32/) You can access photoshop and easily go through your layers and export them.
Here is a code sample that works on the layers within the currently active Photoshop document, and exports them into the folder defined in 'save_location'.
还有 https://code.google.com/p/pypsd/ 和 https://github.com/kmike/psd-tools 用于读取 PSD 文件的 Python 包。
There are also https://code.google.com/p/pypsd/ and https://github.com/kmike/psd-tools Python packages for reading PSD files.
https://github.com/antipalindrome/Photoshop-Export-Layers- to-Files-Fast
这不是用 python 编写的,但这里建议的解决方案对我来说比上面的脚本更具挑战性。如果您想要的功能不仅仅是将图层导出到单个文件,那么您最好使用此处的其他选项。但是,如果您只关心将图层导出到文件,则此脚本可以轻松快速地运行。
https://github.com/antipalindrome/Photoshop-Export-Layers-to-Files-Fast
This is not in python, but the suggested solutions here proved more challenging for me than the above script. If you want the capacity to do more than just export layers to individual files, you're probably better off using the other options here. But if you only care about exporting layers to files, this script works easily and very quickly.
使用 Gimp-Python? http://www.gimp.org/docs/python/index.html
这样您就不需要 Photoshop,它应该可以在任何运行 Gimp 和 Python 的平台上运行。这是一个很大的依赖项,但却是免费的。
要在 PIL 中执行此操作:
编辑:好的,找到解决方案: https://github.com/jerem/psdparse
这将允许您使用 python 从 psd 文件中提取图层,而无需任何非 python 的东西。
Use Gimp-Python? http://www.gimp.org/docs/python/index.html
You don't need Photoshop that way, and it should work on any platform that runs Gimp and Python. It's a large dependency, but a free one.
For doing it in PIL:
Edit: OK, found the solution: https://github.com/jerem/psdparse
This will allow you to extract layers from a psd file with python without any non-python stuff.