def _scale_layer_for_layer_exporter(self, image, layer, layer_exporter): if not pdb.gimp_item_is_group(layer): pdb.gimp_item_transform_scale( layer, layer.offsets[0] * self._preview_scaling_factor, layer.offsets[1] * self._preview_scaling_factor, (layer.offsets[0] + layer.width) * self._preview_scaling_factor, (layer.offsets[1] + layer.height) * self._preview_scaling_factor)
def copy_and_insert_layer(image, layer, parent=None, position=0): layer_copy = pdb.gimp_layer_new_from_drawable(layer, image) pdb.gimp_image_insert_layer(image, layer_copy, parent, position) pdb.gimp_item_set_visible(layer_copy, True) if pdb.gimp_item_is_group(layer_copy): layer_copy = pgpdb.merge_layer_group(layer_copy) return layer_copy
def _layer_exporter_on_after_insert_layer(self, image, layer, layer_exporter): if not pdb.gimp_item_is_group(layer): pdb.gimp_layer_scale( layer, max(1, int(round(layer.width * self._preview_scaling_factor))), max(1, int(round(layer.height * self._preview_scaling_factor))), False)
def copy_and_insert_layer(image, layer, parent=None, position=0): layer_copy = pdb.gimp_layer_new_from_drawable(layer, image) pdb.gimp_image_insert_layer(image, layer_copy, parent, position) pdb.gimp_item_set_visible(layer_copy, True) if pdb.gimp_item_is_group(layer_copy): layer_copy = pg.pdbutils.merge_layer_group(layer_copy) return layer_copy
def _process_layers(image, layer_group, apply_layer_attributes, apply_layer_masks): for layer in layer_group.children: if pdb.gimp_item_is_group(layer): layer = merge_layer_group(layer) else: if layer.opacity != 100.0 or layer.mode != gimpenums.NORMAL_MODE: if apply_layer_attributes: layer = _apply_layer_attributes(image, layer, layer_group) else: layer.opacity = 100.0 layer.mode = gimpenums.NORMAL_MODE if layer.mask is not None: if apply_layer_masks and pdb.gimp_layer_get_apply_mask(layer): pdb.gimp_layer_remove_mask(layer, gimpenums.MASK_APPLY) else: pdb.gimp_layer_remove_mask(layer, gimpenums.MASK_DISCARD)
def merge_layer_group(layer_group): """ Merge layers in the specified layer group belonging to the specified image into one layer. This function can handle both top-level and nested layer groups. """ if not pdb.gimp_item_is_group(layer_group): raise TypeError("'{}': not a layer group".format(layer_group.name)) image = layer_group.image with undo_group(image): orig_parent_and_pos = () if layer_group.parent is not None: # Nested layer group orig_parent_and_pos = (layer_group.parent, pdb.gimp_image_get_item_position( image, layer_group)) pdb.gimp_image_reorder_item(image, layer_group, None, 0) orig_layer_visibility = [layer.visible for layer in image.layers] for layer in image.layers: layer.visible = False layer_group.visible = True merged_layer_group = pdb.gimp_image_merge_visible_layers( image, gimpenums.EXPAND_AS_NECESSARY) for layer, orig_visible in zip(image.layers, orig_layer_visibility): layer.visible = orig_visible if orig_parent_and_pos: pdb.gimp_image_reorder_item(image, merged_layer_group, orig_parent_and_pos[0], orig_parent_and_pos[1]) return merged_layer_group
def merge_layer_group(layer_group): """ Merge layers in the specified layer group belonging to the specified image into one layer. This function can handle both top-level and nested layer groups. """ if not pdb.gimp_item_is_group(layer_group): raise TypeError("'{}': not a layer group".format(layer_group.name)) image = layer_group.image with undo_group(image): orig_parent_and_pos = () if layer_group.parent is not None: # Nested layer group orig_parent_and_pos = ( layer_group.parent, pdb.gimp_image_get_item_position(image, layer_group)) pdb.gimp_image_reorder_item(image, layer_group, None, 0) orig_layer_visibility = [layer.visible for layer in image.layers] for layer in image.layers: layer.visible = False layer_group.visible = True merged_layer_group = pdb.gimp_image_merge_visible_layers( image, gimpenums.EXPAND_AS_NECESSARY) for layer, orig_visible in zip(image.layers, orig_layer_visibility): layer.visible = orig_visible if orig_parent_and_pos: pdb.gimp_image_reorder_item( image, merged_layer_group, orig_parent_and_pos[0], orig_parent_and_pos[1]) return merged_layer_group
def _is_group(self, item): return pdb.gimp_item_is_group(item)