Layers

Layers

PsdImage.layers는 파싱된 각 레이어를 Layer 객체 목록으로 반환합니다. 각 Layer는 자체 기하학, 가시성 및 합성 상태와 채널, 마스크, 블렌딩 범위에 대한 메타데이터를 노출합니다.


레이어 메타데이터 읽기

name, bounds (및 파생된 width/height/top/left/bottom/right), is_visible, opacity, clipping, blend_mode_key, 그리고 channels_count는 모두 직접 읽을 수 있습니다.

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}, "
              f"Visible={layer.is_visible}, Opacity={layer.opacity}, "
              f"BlendMode={layer.blend_mode_key}")

지원되는 메타데이터 편집

name, is_visible, opacity, clipping, blend_mode_key, 및 네 개의 경계(edge) (top/left/bottom/right)는 제자리에서 변경할 수 있으며 PsdImage.save()로 다시 기록할 수 있습니다.

from aspose_psd_foss.psdimage import PsdImage
from aspose_psd_foss.layers.blendmode import BlendMode

with PsdImage.load("input.psd") as image:
    layer = image.layers[0]
    layer.name = f"{layer.name} (edited)"
    layer.is_visible = not layer.is_visible
    layer.opacity = 128
    layer.blend_mode_key = BlendMode.MULTIPLY
    image.save("output.psd")

채널 및 마스크 메타데이터

channel_information, layer_mask_data, 및 layer_blending_ranges_data는 이 FOSS 빌드에서 읽기 전용이며 — 해당 설정자는 NotSupportedException을 발생시킵니다.

layer = image.layers[0]
for channel in layer.channel_information:
    print(f"Channel {channel.ChannelID}: {channel.compression_method}, {channel.length} bytes")

if layer.has_mask_data:
    mask = layer.layer_mask_data
    print(f"Mask bounds: {mask.mask_rectangle}, flags: {mask.flags}")

레이어 제거 또는 재정렬

PsdImage.layers는 getter와 setter를 모두 가집니다: 필터링되거나 재정렬된 리스트를 할당하면 문서의 레이어 컬렉션이 교체됩니다.

from aspose_psd_foss.psdimage import PsdImage

with PsdImage.load("input.psd") as image:
    image.layers = [layer for layer in image.layers if layer.is_visible]
    image.save("output.psd")

팁 및 모범 사례

  • 위치를 기준으로 image.layers에 인덱싱하세요; 리스트 순서는 문서 자체의 레이어 순서와 일치합니다.
  • blend_mode_key는 모든 BlendMode 열거값을 허용합니다 — 문서에 선언된 컬러 모드에 대해 검증이 수행되지 않습니다.
  • channel_information, layer_mask_data, 및 layer_blending_ranges_data는 읽을 수 있지만 절대 재할당될 수 없습니다.
  • 모든 편집이 끝난 후 PsdImage.save()를 한 번 호출하세요; 각 호출은 전체 문서를 기록합니다.

일반적인 문제

문제원인수정
NotSupportedException은(는) channel_information, layer_mask_data 또는 layer_blending_ranges_data를 설정할 때이 세 속성은 setter가 있음에도 불구하고 FOSS 빌드에서는 읽기 전용입니다값을 읽으세요; 재할당을 시도하지 마세요
layer_mask_data 접근 시 마스크가 없을 때모든 레이어에 마스크 하위 섹션이 있는 것은 아닙니다읽기 전에 layer.has_mask_data을 확인하고 layer.layer_mask_data을 읽으세요

FAQ

레이어를 제거할 수 있나요?

예 — image.layers을(를) 필터링된 목록에 재할당합니다.

레이어의 채널 또는 마스크 데이터를 변경할 수 있나요?

아니오. channel_information, layer_mask_data, layer_blending_ranges_data는 읽기 전용이며 — name, is_visible, opacity, clipping, blend_mode_key와 경계 가장자리만 변경할 수 있습니다.


API Reference 요약

클래스/메서드설명
PsdImage.layers레이어 컬렉션을 가져오거나 설정합니다 — 제거/재정렬을 위해 설정 가능
Layer.name / is_visible / opacity / clipping / blend_mode_key / top / left / bottom / right지원되는 레이어 메타데이터 편집
Layer.bounds / width / height / channels_count읽기 전용 레이어 기하학
Layer.channel_information / layer_mask_data / layer_blending_ranges_data읽기 전용 채널/마스크/블렌딩 메타데이터

참조

 한국어