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.
This commit is contained in:
Alx Sa 2026-02-13 14:45:43 +00:00
parent 5f7e82211c
commit b507aae3fc

View file

@ -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);