Gimp.Layer

g GObject.Object GObject.Object Gimp.Item Gimp.Item GObject.Object->Gimp.Item Gimp.Drawable Gimp.Drawable Gimp.Layer Gimp.Layer Gimp.Drawable->Gimp.Layer Gimp.Item->Gimp.Drawable

Subclasses:

Gimp.GroupLayer, Gimp.TextLayer

Methods

Inherited:

Gimp.Drawable (55), Gimp.Item (55), GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

from_mask (mask)

class

get_by_id (layer_id)

class

new (image, name, width, height, type, opacity, mode)

class

new_from_drawable (drawable, dest_image)

class

new_from_pixbuf (image, name, pixbuf, opacity, mode, progress_start, progress_end)

class

new_from_surface (image, name, surface, progress_start, progress_end)

class

new_from_visible (image, dest_image, name)

add_alpha ()

add_mask (mask)

copy ()

create_mask (mask_type)

flatten ()

get_apply_mask ()

get_blend_space ()

get_composite_mode ()

get_composite_space ()

get_edit_mask ()

get_lock_alpha ()

get_mask ()

get_mode ()

get_opacity ()

get_show_mask ()

is_floating_sel ()

remove_mask (mode)

resize (new_width, new_height, offx, offy)

resize_to_image_size ()

scale (new_width, new_height, local_origin)

set_apply_mask (apply_mask)

set_blend_space (blend_space)

set_composite_mode (composite_mode)

set_composite_space (composite_space)

set_edit_mask (edit_mask)

set_lock_alpha (lock_alpha)

set_mode (mode)

set_offsets (offx, offy)

set_opacity (opacity)

set_show_mask (show_mask)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

Inherited:

Gimp.Item (1)

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

Gimp.Drawable

r

Class Details

class Gimp.Layer(**kwargs)
Bases:

Gimp.Drawable

Abstract:

No

Structure:

Gimp.LayerClass

Operations on a single layer.

classmethod from_mask(mask)
Parameters:

mask (Gimp.LayerMask) – Mask for which to return the layer.

Returns:

The mask’s layer.

Return type:

Gimp.Layer

Get the specified mask’s layer.

This procedure returns the specified mask’s layer , or -1 if none exists.

New in version 2.2.

classmethod get_by_id(layer_id)
Parameters:

layer_id (int) – The layer id.

Returns:

a Gimp.Layer for layer_id or None if layer_id does not represent a valid layer. The object belongs to libgimp and you must not modify or unref it.

Return type:

Gimp.Layer or None

Returns a Gimp.Layer representing layer_id. This function calls Gimp.Item.get_by_id() and returns the item if it is layer or None otherwise.

New in version 3.0.

classmethod new(image, name, width, height, type, opacity, mode)
Parameters:
  • image (Gimp.Image) – The image to which to add the layer.

  • name (str or None) – The layer name.

  • width (int) – The layer width.

  • height (int) – The layer height.

  • type (Gimp.ImageType) – The layer type.

  • opacity (float) – The layer opacity.

  • mode (Gimp.LayerMode) – The layer combination mode.

Returns:

The newly created layer. The object belongs to libgimp and you should not free it.

Return type:

Gimp.Layer

Create a new layer.

This procedure creates a new layer with the specified width, height and type. If name is None, a default layer name will be used. opacity and mode are also supplied parameters.

The new layer still needs to be added to the image as this is not automatic. Add the new layer with the [method`Image`.insert_layer] method.

Other attributes such as layer mask modes and offsets should be set with explicit procedure calls.

classmethod new_from_drawable(drawable, dest_image)
Parameters:
  • drawable (Gimp.Drawable) – The source drawable from where the new layer is copied.

  • dest_image (Gimp.Image) – The destination image to which to add the layer.

Returns:

The newly copied layer.

Return type:

Gimp.Layer

Create a new layer by copying an existing drawable.

This procedure creates a new layer as a copy of the specified drawable. The new layer still needs to be added to the image, as this is not automatic. Add the new layer with the Gimp.Image.insert_layer() command. Other attributes such as layer mask modes, and offsets should be set with explicit procedure calls.

classmethod new_from_pixbuf(image, name, pixbuf, opacity, mode, progress_start, progress_end)
Parameters:
Returns:

The newly created layer. The object belongs to libgimp and you should not free it.

Return type:

Gimp.Layer

Create a new layer from a GdkPixbuf.Pixbuf.

This procedure creates a new layer from the given GdkPixbuf.Pixbuf. The image has to be an RGB image and just like with Gimp.Layer.new() you will still need to add the layer to it.

If you pass progress_end > progress_start to this function, Gimp.progress_update() will be called for. You have to call Gimp.progress_init() beforehand then.

New in version 2.2.

classmethod new_from_surface(image, name, surface, progress_start, progress_end)
Parameters:
  • image (Gimp.Image) – The RGB image to which to add the layer.

  • name (str) – The layer name.

  • surface (cairo.Surface) – A Cairo image surface.

  • progress_start (float) – start of progress

  • progress_end (float) – end of progress

Returns:

The newly created layer. The object belongs to libgimp and you should not free it.

Return type:

Gimp.Layer

Create a new layer from a [type`cairo`.Surface].

This procedure creates a new layer from the given [type`cairo`.Surface]. The image has to be an RGB image and just like with Gimp.Layer.new() you will still need to add the layer to it.

If you pass progress_end > progress_start to this function, Gimp.progress_update() will be called for. You have to call Gimp.progress_init() beforehand then.

New in version 2.8.

classmethod new_from_visible(image, dest_image, name)
Parameters:
  • image (Gimp.Image) – The source image from where the content is copied.

  • dest_image (Gimp.Image) – The destination image to which to add the layer.

  • name (str or None) – The layer name.

Returns:

The newly created layer.

Return type:

Gimp.Layer

Create a new layer from what is visible in an image.

This procedure creates a new layer from what is visible in the given image. The new layer still needs to be added to the destination image, as this is not automatic. Add the new layer with the Gimp.Image.insert_layer() command. Other attributes such as layer mask modes, and offsets should be set with explicit procedure calls.

New in version 2.6.

add_alpha()
Returns:

True on success.

Return type:

bool

Add an alpha channel to the layer if it doesn’t already have one.

This procedure adds an additional component to the specified layer if it does not already possess an alpha channel. An alpha channel makes it possible to clear and erase to transparency, instead of the background color. This transforms layers of type RGB to RGBA, GRAY to GRAYA, and INDEXED to INDEXEDA.

add_mask(mask)
Parameters:

mask (Gimp.LayerMask) – The mask to add to the layer.

Returns:

True on success.

Return type:

bool

Add a layer mask to the specified layer.

This procedure adds a layer mask to the specified layer. Layer masks serve as an additional alpha channel for a layer. This procedure will fail if a number of prerequisites aren’t met. The layer cannot already have a layer mask. The specified mask must exist and have the same dimensions as the layer. The layer must have been created for use with the specified image and the mask must have been created with the procedure ‘gimp-layer-create-mask’.

copy()
Returns:

The newly copied layer. The object belongs to libgimp and you should not free it.

Return type:

Gimp.Layer

Copy a layer.

This procedure copies the specified layer and returns the copy. The newly copied layer is for use within the original layer’s image. It should not be subsequently added to any other image.

create_mask(mask_type)
Parameters:

mask_type (Gimp.AddMaskType) – The type of mask.

Returns:

The newly created mask.

Return type:

Gimp.LayerMask

Create a layer mask for the specified layer.

This procedure creates a layer mask for the specified layer. Layer masks serve as an additional alpha channel for a layer. Different types of masks are allowed for initialisation:

  • white mask (leaves the layer fully visible);

  • black mask (gives the layer complete transparency);

  • the layer’s alpha channel (either a copy, or a transfer, which leaves the layer fully visible, but which may be more useful than a white mask);

  • the current selection;

  • a grayscale copy of the layer;

  • or a copy of the active channel.

The layer mask still needs to be added to the layer. This can be done with a call to Gimp.Layer.add_mask().

Gimp.Layer.create_mask() will fail if there are no active channels on the image, when called with ‘ADD-CHANNEL-MASK’. It will return a black mask when called with ‘ADD-ALPHA-MASK’ or ‘ADD-ALPHA-TRANSFER-MASK’ on a layer with no alpha channels, or with ‘ADD-SELECTION-MASK’ when there is no selection on the image.

flatten()
Returns:

True on success.

Return type:

bool

Remove the alpha channel from the layer if it has one.

This procedure removes the alpha channel from a layer, blending all (partially) transparent pixels in the layer against the background color. This transforms layers of type RGBA to RGB, GRAYA to GRAY, and INDEXEDA to INDEXED.

New in version 2.4.

get_apply_mask()
Returns:

The layer’s apply mask setting.

Return type:

bool

Get the apply mask setting of the specified layer.

This procedure returns the specified layer’s apply mask setting. If the value is True, then the layer mask for this layer is currently being composited with the layer’s alpha channel.

get_blend_space()
Returns:

The layer blend space.

Return type:

Gimp.LayerColorSpace

Get the blend space of the specified layer.

This procedure returns the specified layer’s blend space.

New in version 2.10.

get_composite_mode()
Returns:

The layer composite mode.

Return type:

Gimp.LayerCompositeMode

Get the composite mode of the specified layer.

This procedure returns the specified layer’s composite mode.

New in version 2.10.

get_composite_space()
Returns:

The layer composite space.

Return type:

Gimp.LayerColorSpace

Get the composite space of the specified layer.

This procedure returns the specified layer’s composite space.

New in version 2.10.

get_edit_mask()
Returns:

The layer’s edit mask setting.

Return type:

bool

Get the edit mask setting of the specified layer.

This procedure returns the specified layer’s edit mask setting. If the value is True, then the layer mask for this layer is currently active, and not the layer.

get_lock_alpha()
Returns:

The layer’s lock alpha channel setting.

Return type:

bool

Get the lock alpha channel setting of the specified layer.

This procedure returns the specified layer’s lock alpha channel setting.

get_mask()
Returns:

The layer mask.

Return type:

Gimp.LayerMask

Get the specified layer’s mask if it exists.

This procedure returns the specified layer’s mask, or -1 if none exists.

get_mode()
Returns:

The layer combination mode.

Return type:

Gimp.LayerMode

Get the combination mode of the specified layer.

This procedure returns the specified layer’s combination mode.

get_opacity()
Returns:

The layer opacity.

Return type:

float

Get the opacity of the specified layer.

This procedure returns the specified layer’s opacity.

get_show_mask()
Returns:

The layer’s show mask setting.

Return type:

bool

Get the show mask setting of the specified layer.

This procedure returns the specified layer’s show mask setting. This controls whether the layer or its mask is visible. True indicates that the mask should be visible. If the layer has no mask, then this function returns an error.

is_floating_sel()
Returns:

True if the layer is a floating selection.

Return type:

bool

Is the specified layer a floating selection?

This procedure returns whether the layer is a floating selection. Floating selections are special cases of layers which are attached to a specific drawable.

remove_mask(mode)
Parameters:

mode (Gimp.MaskApplyMode) – Removal mode.

Returns:

True on success.

Return type:

bool

Remove the specified layer mask from the layer.

This procedure removes the specified layer mask from the layer. If the mask doesn’t exist, an error is returned.

resize(new_width, new_height, offx, offy)
Parameters:
  • new_width (int) – New layer width.

  • new_height (int) – New layer height.

  • offx (int) – x offset between upper left corner of old and new layers: (old - new).

  • offy (int) – y offset between upper left corner of old and new layers: (old - new).

Returns:

True on success.

Return type:

bool

Resize the layer to the specified extents.

This procedure resizes the layer so that its new width and height are equal to the supplied parameters. Offsets are also provided which describe the position of the previous layer’s content. This operation only works if the layer has been added to an image.

resize_to_image_size()
Returns:

True on success.

Return type:

bool

Resize a layer to the image size.

This procedure resizes the layer so that it’s new width and height are equal to the width and height of its image container.

scale(new_width, new_height, local_origin)
Parameters:
  • new_width (int) – New layer width.

  • new_height (int) – New layer height.

  • local_origin (bool) – Use a local origin (as opposed to the image origin).

Returns:

True on success.

Return type:

bool

Scale the layer using the default interpolation method.

This procedure scales the layer so that its new width and height are equal to the supplied parameters. The ‘local-origin’ parameter specifies whether to scale from the center of the layer, or from the image origin. This operation only works if the layer has been added to an image. The interpolation method used can be set with Gimp.context_set_interpolation().

set_apply_mask(apply_mask)
Parameters:

apply_mask (bool) – The new layer’s apply mask setting.

Returns:

True on success.

Return type:

bool

Set the apply mask setting of the specified layer.

This procedure sets the specified layer’s apply mask setting. This controls whether the layer’s mask is currently affecting the alpha channel. If there is no layer mask, this function will return an error.

set_blend_space(blend_space)
Parameters:

blend_space (Gimp.LayerColorSpace) – The new layer blend space.

Returns:

True on success.

Return type:

bool

Set the blend space of the specified layer.

This procedure sets the specified layer’s blend space.

New in version 2.10.

set_composite_mode(composite_mode)
Parameters:

composite_mode (Gimp.LayerCompositeMode) – The new layer composite mode.

Returns:

True on success.

Return type:

bool

Set the composite mode of the specified layer.

This procedure sets the specified layer’s composite mode.

New in version 2.10.

set_composite_space(composite_space)
Parameters:

composite_space (Gimp.LayerColorSpace) – The new layer composite space.

Returns:

True on success.

Return type:

bool

Set the composite space of the specified layer.

This procedure sets the specified layer’s composite space.

New in version 2.10.

set_edit_mask(edit_mask)
Parameters:

edit_mask (bool) – The new layer’s edit mask setting.

Returns:

True on success.

Return type:

bool

Set the edit mask setting of the specified layer.

This procedure sets the specified layer’s edit mask setting. This controls whether the layer or it’s mask is currently active for editing. If the specified layer has no layer mask, then this procedure will return an error.

set_lock_alpha(lock_alpha)
Parameters:

lock_alpha (bool) – The new layer’s lock alpha channel setting.

Returns:

True on success.

Return type:

bool

Set the lock alpha channel setting of the specified layer.

This procedure sets the specified layer’s lock alpha channel setting.

set_mode(mode)
Parameters:

mode (Gimp.LayerMode) – The new layer combination mode.

Returns:

True on success.

Return type:

bool

Set the combination mode of the specified layer.

This procedure sets the specified layer’s combination mode.

set_offsets(offx, offy)
Parameters:
  • offx (int) – Offset in x direction.

  • offy (int) – Offset in y direction.

Returns:

True on success.

Return type:

bool

Set the layer offsets.

This procedure sets the offsets for the specified layer. The offsets are relative to the image origin and can be any values. This operation is valid only on layers which have been added to an image.

set_opacity(opacity)
Parameters:

opacity (float) – The new layer opacity.

Returns:

True on success.

Return type:

bool

Set the opacity of the specified layer.

This procedure sets the specified layer’s opacity.

set_show_mask(show_mask)
Parameters:

show_mask (bool) – The new layer’s show mask setting.

Returns:

True on success.

Return type:

bool

Set the show mask setting of the specified layer.

This procedure sets the specified layer’s show mask setting. This controls whether the layer or its mask is visible. True indicates that the mask should be visible. If there is no layer mask, this function will return an error.