摘要:
2023-10-09 python-使用psd_tools-读取psd信息及导出图层图片-记录
相关文档:
Usage — psd-tools 1.9.28 documentation
读取psd的信息:
py代码:
from psd_tools import PSDImage
psd = PSDImage.open('example.psd')
#psd = PSDImage.open('one.psd')
print(psd)
for layer in psd:
print(layer)
print(layer.name)
print(layer.size)
输出结果:
[root@dev-stonedb-zhangshilong1 psd]# python3 p01.py
PSDImage(mode=ColorMode.RGB size=657x876 depth=8 channels=4)
PixelLayer('图层 0' size=657x876)
图层 0
(657, 876)
PixelLayer('图层 1' size=657x734)
图层 1
(657, 734)
PixelLayer('图层 2' size=94x42)
图层 2
(94, 42)
PixelLayer('图层 1 副本' size=657x734)
图层 1 副本
(657, 734)
导出图层的图片:
export参数命令:
[root@dev-stonedb-zhangshilong1 psd]# psd-tools --help export
psd-tools command line utility.
Usage:
psd-tools export <input_file> <output_file> [options]
psd-tools show <input_file> [options]
psd-tools debug <input_file> [options]
psd-tools -h | --help
psd-tools --version
Options:
-v --verbose Be more verbose.
Example:
psd-tools show example.psd # Show the file content
psd-tools export example.psd example.png # Export as PNG
psd-tools export example.psd[0] example-0.png # Export layer as PNG
具体执行命令:
psd-tools show example.psd
psd-tools export example.psd[0] example-0.png
psd-tools export example.psd[1] example-1.png
psd-tools export example.psd[2] example-2.png
psd-tools export example.psd[3] example-3.png