Skip to content

Instantly share code, notes, and snippets.

@fre-sch
Last active January 28, 2023 10:51
Show Gist options
  • Save fre-sch/5c8ca933854594a22c37aeb2721e7085 to your computer and use it in GitHub Desktop.
Save fre-sch/5c8ca933854594a22c37aeb2721e7085 to your computer and use it in GitHub Desktop.
Gimp Python-Fu script that copies selection to new layer and autocrops layer.
#!/usr/bin/env python
from gimpfu import *
def python_selection_to_layer_cropped(image, drawable, layer_name):
pdb.gimp_image_undo_group_start(image)
prev_layer = image.active_layer
pdb.gimp_edit_copy(image.active_layer)
fsel = pdb.gimp_edit_paste(drawable, False)
pdb.gimp_floating_sel_to_layer(fsel)
image.active_layer.name = layer_name
pdb.plug_in_autocrop_layer(image, image.active_layer)
image.active_layer = prev_layer
pdb.gimp_image_undo_group_end(image)
register(
"python_fu_selection_to_layer_cropped",
"Create new layer from selection and auto crop layer",
"Create new layer from selection and auto crop layer",
"https://github.com/fre-sch",
"https://github.com/fre-sch",
"2016",
"<Image>/Filters/Selection to Layer (cropped)...",
"RGB*, GRAY*",
[
(PF_STRING, "layer_name", "Name for new layer", ""),
],
[],
python_selection_to_layer_cropped
)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment