From b507aae3fc185a4db9caf1702c8d6c4c0909cc47 Mon Sep 17 00:00:00 2001 From: Alx Sa Date: Fri, 13 Feb 2026 14:45:43 +0000 Subject: [PATCH] tools: Add alpha if crop can grow the layer This patch conditionally adds an alpha channel to a layer when using the Crop Tool, under the following conditions: 1) "Selected layers only" is checked 2) "Allow growing" is checked 3) "Fill with" is set to transparency 4) The crop rectangle is larger than the width or height of the layer 5) The layer does not already have an alpha channel. --- app/tools/gimpcroptool.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/tools/gimpcroptool.c b/app/tools/gimpcroptool.c index 6f4225d022..d38bcb57d7 100644 --- a/app/tools/gimpcroptool.c +++ b/app/tools/gimpcroptool.c @@ -25,10 +25,12 @@ #include "tools-types.h" #include "core/gimp.h" +#include "core/gimpdrawable.h" #include "core/gimpimage.h" #include "core/gimpimage-crop.h" #include "core/gimpimage-undo.h" #include "core/gimpitem.h" +#include "core/gimplayer.h" #include "core/gimptoolinfo.h" #include "widgets/gimphelp-ids.h" @@ -496,6 +498,18 @@ gimp_crop_tool_commit (GimpCropTool *crop_tool) off_x -= x; off_y -= y; + /* If we have the crop tool set to allow growing and to fill + * with transparency, and the crop rectangle is larger than + * the layer, then we add transparency if there is none */ + if (options->allow_growing && + (gimp_item_get_width (GIMP_ITEM (iter->data)) < w || + gimp_item_get_width (GIMP_ITEM (iter->data)) < h) && + options->fill_type == GIMP_FILL_TRANSPARENT && + ! gimp_drawable_has_alpha (GIMP_DRAWABLE (iter->data))) + { + gimp_layer_add_alpha (GIMP_LAYER (iter->data)); + } + gimp_item_resize (GIMP_ITEM (iter->data), GIMP_CONTEXT (options), options->fill_type, w, h, off_x, off_y);