Quickstart

快速入门

此示例加载一个 PSD/PSB 文档,打印其标题和图层元数据,重命名第一个图层,并保存结果。


前置条件

要求细节
Python受支持的 CPython 解释器
PackageAspose.PSD FOSS 用于 Python 已安装 — 请参见 Installation

  1. 加载文档并打印其标题。
from aspose_psd_foss.psdimage import PsdImage

with PsdImage.load("input.psd") as image:
    print(f"Width: {image.width}, Height: {image.height}")
    print(f"ColorMode: {image.color_mode}, Version: {image.version}")
  1. 打印每个图层的元数据。
from aspose_psd_foss.psdimage import PsdImage

with PsdImage.load("input.psd") as image:
    for layer in image.layers:
        print(f"{layer.name}: {layer.bounds}, Visible={layer.is_visible}")
  1. 重命名第一个图层并保存结果。
from aspose_psd_foss.psdimage import PsdImage

with PsdImage.load("input.psd") as image:
    if image.layer_count > 0:
        image.layers[0].name = f"{image.layers[0].name} (edited)"
    image.save("output.psd")

后续步骤

另请参阅

 中文