Skip to content

Instantly share code, notes, and snippets.

@fre-sch
Last active January 28, 2023 10:51
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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