Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

Fix: Improve non square bbox coverage for linear gradient tool. (#8889)

DustyShoec8dfea868145
diff --git a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasTool/CanvasGradientToolModule.ts b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasTool/CanvasGradientToolModule.ts
index 745a541735..3decb8636d 100644
--- a/invokeai/frontend/web/src/features/controlLayers/konva/CanvasTool/CanvasGradientToolModule.ts
+++ b/invokeai/frontend/web/src/features/controlLayers/konva/CanvasTool/CanvasGradientToolModule.ts
@@ -134,19 +134,14 @@ export class CanvasGradientToolModule extends CanvasModuleBase {
};
if (settings.gradientType === 'linear') {
- const bboxCenter = {
- x: bboxInLayer.x + bboxInLayer.width / 2,
- y: bboxInLayer.y + bboxInLayer.height / 2,
- };
- const cos = Math.cos(angle);
- const sin = Math.sin(angle);
- const halfWidth = (Math.abs(bboxInLayer.width * cos) + Math.abs(bboxInLayer.height * sin)) / 2;
- const halfHeight = (Math.abs(bboxInLayer.width * sin) + Math.abs(bboxInLayer.height * cos)) / 2;
+ // Always render linear gradients on a rect that fully covers the bbox.
+ // Angle-dependent rect sizing can undershoot on non-square bboxes (e.g. 90deg on tall bboxes),
+ // leaving uncovered bands when the result is clipped back to bbox.
rect = {
- x: bboxCenter.x - halfWidth,
- y: bboxCenter.y - halfHeight,
- width: Math.max(halfWidth * 2, 1),
- height: Math.max(halfHeight * 2, 1),
+ x: bboxInLayer.x,
+ y: bboxInLayer.y,
+ width: Math.max(bboxInLayer.width, 1),
+ height: Math.max(bboxInLayer.height, 1),
};
}