Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException
Border size must be greater than or equal to 0
Error message
Border size must be greater than or equal to 0
What it means
Drawables (Rectangle, Ellipse, Circle, Polygon, Line, Bezier — anything using the HasBorder trait) reject negative border sizes. A border thickness of 0 is valid and means 'no border'; negative values have no rendering meaning and fail fast in setBorderSize(). Note that setBorder($color, $size) delegates to this setter, so the error can surface from either method.
Source
Thrown at src/Geometry/Traits/HasBorder.php:37
*
* @throws InvalidArgumentException
*/
public function setBorder(string|ColorInterface $color, int $size = 1): self
{
return $this->setBorderSize($size)->setBorderColor($color);
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::setBorderSize()
*
* @throws InvalidArgumentException
*/
public function setBorderSize(int $size): self
{
if ($size < 0) {
throw new InvalidArgumentException(
'Border size must be greater than or equal to 0',
);
}
$this->borderSize = $size;
return $this;
}
/**
* {@inheritdoc}
*
* @see DrawableInterface::borderSize()
*/
public function borderSize(): int
{
return $this->borderSize;
}View on GitHub (pinned to 5598b9e397)
Solutions
- Pass 0 to disable the border: setBorderSize(0) or setBorder($color, 0)
- Clamp computed sizes: max(0, $calculatedBorderSize)
- Validate user-supplied border thickness as int >= 0 before applying
Example fix
// before
$shape->setBorder('fff', -1); // attempt to remove border
// after
$shape->setBorder('fff', 0); // border disabled Defensive patterns
Strategy: validation
Validate before calling
$border = max(0, $thickness); // or use 0 explicitly to disable $shape->setBorderSize($border);
Type guard
function isValidBorderSize(int $size): bool
{
return $size >= 0;
} Try / catch
try {
$shape->setBorder('fff', $size);
} catch (InvalidArgumentException $e) {
$shape->setBorder('fff', 0); // degrade to no border
} Prevention
- Use 0, not a negative value, to remove a border
- Validate user-supplied thickness as int >= 0 at the input layer
- Watch subtraction idioms ($a - $b) that can go negative
When it happens
Trigger: $rectangle->setBorderSize(-1), or $rectangle->setBorder('fff', -2). Triggered by any drawable using HasBorder, including via tests exercising setBorder/setBorderSize.
Common situations: Trying to 'remove' a border by passing a negative size instead of 0, or computing border thickness from user input / diff arithmetic that goes negative (e.g. $size - $inset where $inset > $size).
Related errors
- Failed to apply Intervention\Image\Drivers\Gd\Modifiers\Draw
- Height must be greater than or equal to 1
- Unable to parse RGB color from input "{input}"
- Invalid cmyk() color syntax "{input}"
- Unable to parse HSL color from input "{input}"
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/d76b9b517ad6fbd6.
Report an issue: GitHub.