psd_tools.psd.layer_and_mask

Layer and mask data structure.

LayerAndMaskInformation

class psd_tools.psd.layer_and_mask.LayerAndMaskInformation(layer_info=None, global_layer_mask_info=None, tagged_blocks=None)[source]

Layer and mask information section.

layer_info

See LayerInfo.

global_layer_mask_info

See GlobalLayerMaskInfo.

tagged_blocks

See TaggedBlocks.

global_layer_mask_info
layer_info
classmethod read(fp, encoding='macroman', version=1)[source]

Read the element from a file-like object.

Parameters:
  • fp – file-like object
  • encoding – encoding of the string
  • version – psd file version
Return type:

LayerAndMaskInformation

tagged_blocks
write(fp, encoding='macroman', version=1, padding=4)[source]

Write the element to a file-like object.

Parameters:
  • fp – file-like object
  • encoding – encoding of the string
  • version – psd file version

LayerInfo

class psd_tools.psd.layer_and_mask.LayerInfo(layer_count: int = 0, layer_records=None, channel_image_data=None)[source]

High-level organization of the layer information.

layer_count

Layer count. If it is a negative number, its absolute value is the number of layers and the first alpha channel contains the transparency data for the merged result.

layer_records

Information about each layer. See LayerRecords.

channel_image_data

Channel image data. Contains one or more image data records. See ChannelImageData.

channel_image_data
layer_count
layer_records
classmethod read(fp, encoding='macroman', version=1)[source]

Read the element from a file-like object.

Parameters:
  • fp – file-like object
  • encoding – encoding of the string
  • version – psd file version
Return type:

LayerInfo

write(fp, encoding='macroman', version=1, padding=4)[source]

Write the element to a file-like object.

Parameters:fp – file-like object
Return type:int

GlobalLayerMaskInfo

class psd_tools.psd.layer_and_mask.GlobalLayerMaskInfo(overlay_color=None, opacity: int = 0, kind=<GlobalLayerMaskKind.PER_LAYER: 128>)[source]

Global mask information.

overlay_color

Overlay color space (undocumented) and color components.

opacity

Opacity. 0 = transparent, 100 = opaque.

kind

Kind. 0 = Color selected–i.e. inverted; 1 = Color protected; 128 = use value stored per layer. This value is preferred. The others are for backward compatibility with beta versions.

kind
opacity
overlay_color
classmethod read(fp)[source]

Read the element from a file-like object.

Parameters:fp – file-like object
Return type:GlobalLayerMaskInfo
write(fp)[source]

Write the element to a file-like object.

Parameters:fp – file-like object

LayerRecords

class psd_tools.psd.layer_and_mask.LayerRecords(items=NOTHING)[source]

List of layer records. See LayerRecord.

classmethod read(fp, layer_count, encoding='macroman', version=1)[source]

Read the element from a file-like object.

Parameters:fp – file-like object
Return type:LayerRecords

LayerRecord

class psd_tools.psd.layer_and_mask.LayerRecord(top: int = 0, left: int = 0, bottom: int = 0, right: int = 0, channel_info=NOTHING, signature: bytes = b'8BIM', blend_mode=<BlendMode.NORMAL: b'norm'>, opacity: int = 255, clipping=<Clipping.BASE: 0>, flags=NOTHING, mask_data=None, blending_ranges=NOTHING, name: str = '', tagged_blocks=NOTHING)[source]

Layer record.

top

Top position.

left

Left position.

bottom

Bottom position.

right

Right position.

channel_info

List of ChannelInfo.

signature

Blend mode signature b'8BIM'.

blend_mode

Blend mode key. See BlendMode.

opacity

Opacity, 0 = transparent, 255 = opaque.

clipping

Clipping, 0 = base, 1 = non-base. See Clipping.

flags

See LayerFlags.

mask_data

MaskData or None.

blending_ranges

See LayerBlendingRanges.

name

Layer name.

tagged_blocks

See TaggedBlocks.

blend_mode
blending_ranges
bottom
channel_info
channel_sizes

List of channel sizes: [(width, height)].

clipping
flags
height

Height of the layer.

left
mask_data
name
opacity
classmethod read(fp, encoding='macroman', version=1)[source]

Read the element from a file-like object.

Parameters:
  • fp – file-like object
  • encoding – encoding of the string
  • version – psd file version
Return type:

LayerRecord

right
signature
tagged_blocks
top
width

Width of the layer.

write(fp, encoding='macroman', version=1)[source]

Write the element to a file-like object.

Parameters:
  • fp – file-like object
  • encoding – encoding of the string
  • version – psd file version

LayerFlags

class psd_tools.psd.layer_and_mask.LayerFlags(transparency_protected: bool = False, visible: bool = True, obsolete: bool = False, photoshop_v5_later: bool = True, pixel_data_irrelevant: bool = False, undocumented_1: bool = False, undocumented_2: bool = False, undocumented_3: bool = False)[source]

Layer flags.

Note there are undocumented flags. Maybe photoshop version.

transparency_protected
visible
pixel_data_irrelevant
obsolete
photoshop_v5_later
pixel_data_irrelevant
classmethod read(fp)[source]

Read the element from a file-like object.

Parameters:fp – file-like object
Return type:LayerFlags
transparency_protected
undocumented_1
undocumented_2
undocumented_3
visible
write(fp)[source]

Write the element to a file-like object.

Parameters:fp – file-like object

LayerBlendingRanges

class psd_tools.psd.layer_and_mask.LayerBlendingRanges(composite_ranges=NOTHING, channel_ranges=NOTHING)[source]

Layer blending ranges.

All ranges contain 2 black values followed by 2 white values.

composite_ranges

List of composite gray blend source and destination ranges.

channel_ranges

List of channel source and destination ranges.

channel_ranges
composite_ranges
classmethod read(fp)[source]

Read the element from a file-like object.

Parameters:fp – file-like object
Return type:LayerBlendingRanges
write(fp)[source]

Write the element to a file-like object.

Parameters:fp – file-like object

MaskData

class psd_tools.psd.layer_and_mask.MaskData(top: int = 0, left: int = 0, bottom: int = 0, right: int = 0, background_color: int = 0, flags=NOTHING, parameters=None, real_flags=None, real_background_color=None, real_top=None, real_left=None, real_bottom=None, real_right=None)[source]

Mask data.

Real user mask is a final composite mask of vector and pixel masks.

top

Top position.

left

Left position.

bottom

Bottom position.

right

Right position.

background_color

Default color. 0 or 255.

flags

See MaskFlags.

parameters

MaskParameters or None.

real_flags

Real user mask flags. See MaskFlags.

real_background_color

Real user mask background. 0 or 255.

real_top

Top position of real user mask.

real_left

Left position of real user mask.

real_bottom

Bottom position of real user mask.

real_right

Right position of real user mask.

background_color
bottom
flags
height

Height of the mask.

left
parameters
classmethod read(fp)[source]

Read the element from a file-like object.

Parameters:fp – file-like object
Return type:MaskData or None
real_background_color
real_bottom
real_flags
real_height

Height of real user mask.

real_left
real_right
real_top
real_width

Width of real user mask.

right
top
width

Width of the mask.

write(fp)[source]

Write the element to a file-like object.

Parameters:fp – file-like object

MaskFlags

class psd_tools.psd.layer_and_mask.MaskFlags(pos_relative_to_layer: bool = False, mask_disabled: bool = False, invert_mask: bool = False, user_mask_from_render: bool = False, parameters_applied: bool = False, undocumented_1: bool = False, undocumented_2: bool = False, undocumented_3: bool = False)[source]

Mask flags.

pos_relative_to_layer

Position relative to layer.

mask_disabled

Layer mask disabled.

invert_mask

Invert layer mask when blending (Obsolete).

user_mask_from_render

The user mask actually came from rendering other data.

parameters_applied

The user and/or vector masks have parameters applied to them.

invert_mask
mask_disabled
parameters_applied
pos_relative_to_layer
classmethod read(fp)[source]

Read the element from a file-like object.

Parameters:fp – file-like object
Return type:MaskFlags
undocumented_1
undocumented_2
undocumented_3
user_mask_from_render
write(fp)[source]

Write the element to a file-like object.

Parameters:fp – file-like object

MaskParameters

class psd_tools.psd.layer_and_mask.MaskParameters(user_mask_density=None, user_mask_feather=None, vector_mask_density=None, vector_mask_feather=None)[source]

Mask parameters.

user_mask_density
user_mask_feather
vector_mask_density
vector_mask_feather
classmethod read(fp)[source]

Read the element from a file-like object.

Parameters:fp – file-like object
Return type:MaskParameters
user_mask_density
user_mask_feather
vector_mask_density
vector_mask_feather
write(fp)[source]

Write the element to a file-like object.

Parameters:fp – file-like object

ChannelInfo

class psd_tools.psd.layer_and_mask.ChannelInfo(id=<ChannelID.CHANNEL_0: 0>, length: int = 0)[source]

Channel information.

id

Channel ID: 0 = red, 1 = green, etc.; -1 = transparency mask; -2 = user supplied layer mask, -3 real user supplied layer mask (when both a user mask and a vector mask are present). See ChannelID.

length

Length of the corresponding channel data.

id
length
classmethod read(fp, version=1)[source]

Read the element from a file-like object.

Parameters:
  • fp – file-like object
  • version – psd file version
Return type:

ChannelInfo

write(fp, version=1)[source]

Write the element to a file-like object.

Parameters:
  • fp – file-like object
  • version – psd file version

ChannelImageData

class psd_tools.psd.layer_and_mask.ChannelImageData(items=NOTHING)[source]

List of channel image data.

See ChannelDataList.

classmethod read(fp, layer_records=None)[source]

Read the element from a file-like object.

Parameters:fp – file-like object
Return type:ChannelImageData
write(fp, **kwargs)[source]

Write the element to a file-like object.

Parameters:fp – file-like object

ChannelDataList

class psd_tools.psd.layer_and_mask.ChannelDataList(items=NOTHING)[source]

List of channel image data.

See ChannelData.

classmethod read(fp, channel_info)[source]

Read the element from a file-like object.

Parameters:
Return type:

ChannelDataList

ChannelData

class psd_tools.psd.layer_and_mask.ChannelData(compression=<Compression.RAW: 0>, data: bytes = b'')[source]

Channel data.

compression

Compression type. See Compression.

data

Data.

compression
data
get_data(width, height, depth, version=1)[source]

Get decompressed channel data.

Parameters:
  • width – width.
  • height – height.
  • depth – bit depth of the pixel.
  • version – psd file version.
Return type:

bytes

classmethod read(fp)[source]

Read the element from a file-like object.

Parameters:fp – file-like object
Return type:ChannelData
set_data(data, width, height, depth, version=1)[source]

Set raw channel data and compress to store.

Parameters:
  • data – raw data bytes to write.
  • compression – compression type, see Compression.
  • width – width.
  • height – height.
  • depth – bit depth of the pixel.
  • version – psd file version.
write(fp, **kwargs)[source]

Write the element to a file-like object.

Parameters:fp – file-like object