photoshop-python-api icon indicating copy to clipboard operation
photoshop-python-api copied to clipboard

The export artboard function exports the size of the entire psd canvas

Open JHD1159351858 opened this issue 10 months ago • 2 comments

I hid all other artboards and exported the current artboard, but the image was the size of the psd canvas.

Image

Image

JHD1159351858 avatar Feb 14 '25 08:02 JHD1159351858

for layer in doc.layers: layer.visible = False # for ab in artboards: # ab.visible = False # 遍历每个图层组,仅显示当前图层组进行导出 for artboard in artboards: artboard.visible = True # 只显示当前图层组 pic_name = artboard.name export_path_new = os.path.join(export_dir, f"{pic_name}.png")

                    # 复制当前文档,避免对原始文档做不可逆修改
                    dup_doc = doc.duplicate()  # 复制文档

                    # 对复制文档执行裁剪,移除连续的透明区域
                    # 注意:这里的 TrimType 和 SaveOptions 根据你的 ps_app API 可能需要调整
                    dup_doc.trim(ps_app.TrimType.TransparentPixels, True, True, True, True)

                    # 配置 PNG 保存选项
                    png_options = ps_app.PNGSaveOptions()

                    # 导出裁剪后的图像
                    dup_doc.saveAs(export_path_new, png_options, asCopy=True)
                    print(f"已导出图层组 '{artboard.name}' 为 PNG,路径:{export_path_new}")

                    # 关闭副本文档,不保存修改
                    dup_doc.close(ps_app.SaveOptions.DONOTSAVECHANGES)

                    artboard.visible = False  # 恢复当前图层组为隐藏状态

JHD1159351858 avatar Feb 14 '25 08:02 JHD1159351858

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


for layer in doc.layers: layer.visible = False # for ab in artboards: # ab.visible = False # traverse each layer group, display only the current layer group for export for artboard in artboards: artboard.visible = True # Show only the current layer group pic_name = artboard.name export_path_new = os.path.join(export_dir, f"{pic_name}.png")

                    # Copy the current document to avoid irreversible modifications to the original document
                    dup_doc = doc.duplicate() # Copy the document

                    # Perform cropping on the copied document to remove continuous transparent areas
                    # Note: TrimType and SaveOptions here may need to be adjusted according to your ps_app API
                    dup_doc.trim(ps_app.TrimType.TransparentPixels, True, True, True, True)

                    # Configure PNG save options
                    png_options = ps_app.PNGSaveOptions()

                    # Export cropped images
                    dup_doc.saveAs(export_path_new, png_options, asCopy=True)
                    print(f"Exported layer group '{artboard.name}' is PNG, path: {export_path_new}")

                    # Close the copy of this document without saving the modification
                    dup_doc.close(ps_app.SaveOptions.DONOTSAVECHANGES)

                    artboard.visible = False # Restore the current layer group to a hidden state  

Issues-translate-bot avatar Feb 14 '25 08:02 Issues-translate-bot