Intervention/image · error · InvalidArgumentException
You must specify either 3 or 4 points to create a bezier cur
Error message
You must specify either 3 or 4 points to create a bezier curve
What it means
The GD driver's bezier implementation only supports quadratic curves (exactly 3 control points) and cubic curves (exactly 4 control points). apply() runs validatePointCount() before anything is drawn and throws InvalidArgumentException for any other point count. This is pure API input validation - the image is untouched when it fires.
Source
Thrown at src/Drivers/Gd/Modifiers/DrawBezierModifier.php:62
if ($this->drawable->hasBorder() && $this->drawable->borderSize() > 0) {
$borderColor = $this->driver()->colorProcessor($image)->export($this->borderColor());
$this->drawBezierBorder($frame->native(), $polygon, $polygonBorderSegments, $borderColor);
}
}
return $image;
}
/**
* Validate that the drawable has exactly 3 or 4 points.
*
* @throws InvalidArgumentException
*/
private function validatePointCount(): void
{
if ($this->drawable->count() !== 3 && $this->drawable->count() !== 4) {
throw new InvalidArgumentException('You must specify either 3 or 4 points to create a bezier curve');
}
}
/**
* Draw the bezier polygon with the background color.
*
* @param array<mixed> $polygon
* @throws ModifierException
*/
private function drawBezierBackground(GdImage $canvas, array $polygon, int $color): void
{
imagesetthickness($canvas, 0);
$this->abortUnless(imagefilledpolygon($canvas, $polygon, $color), 'Unable to draw bezier background');
}
/**
* Draw the bezier border, using thin lines for size 1 or filled polygon segments otherwise
*View on GitHub (pinned to 5598b9e397)
Solutions
- Provide exactly 3 points (quadratic) or exactly 4 points (cubic)
- Split longer paths into several drawBezier() calls of 3 or 4 points each
- Use drawPolygon() or drawLine() for arbitrary point chains
- Check $bezier->count() before calling $image->drawBezier($bezier)
Example fix
// before: two points do not define a curve
$image->drawBezier(fn($b) => $b->point(0, 100)->point(100, 100));
// after: three points define a quadratic bezier
$image->drawBezier(fn($b) => $b
->point(0, 100)
->point(50, 0)
->point(100, 100)); Defensive patterns
Strategy: validation
Validate before calling
use Intervention\Image\Geometry\Bezier;
use Intervention\Image\Geometry\Point;
$bezier = new Bezier();
$bezier->addPoint(new Point(0, 100));
$bezier->addPoint(new Point(50, 0));
$bezier->addPoint(new Point(100, 100));
if (!in_array($bezier->count(), [3, 4], true)) {
throw new InvalidArgumentException(
'Bezier needs exactly 3 or 4 points, got ' . $bezier->count()
);
}
$image->drawBezier($bezier); Type guard
use Intervention\Image\Geometry\Bezier;
function isDrawableBezier(Bezier $bezier): bool
{
return in_array($bezier->count(), [3, 4], true);
} Try / catch
use Intervention\Image\Exceptions\InvalidArgumentException;
try {
$image->drawBezier($bezier);
} catch (InvalidArgumentException $e) {
// fix the point list, or draw a polygon with the same points instead
$image->drawPolygon($bezier);
} Prevention
- Build the Bezier object first, assert count() is 3 or 4, then draw.
- Cover dynamically generated point lists with a unit test on the count.
- Remember the GD bezier is a single quadratic/cubic segment, not a polycurve.
When it happens
Trigger: $image->drawBezier() with a closure or Bezier object holding 2 points or 5+ points; data-driven point lists whose length varies at runtime; loops that accidentally append the starting point again as an end point; passing a Bezier built for a different shape.
Common situations: Converting SVG path data or design-tool exports to drawing code; generating diagrams from variable-length coordinate arrays; assuming drawBezier() accepts arbitrary point chains like drawPolygon().
Related errors
- The specified position ({x}, {y}) is not within the image ar
- Invalid image size
- GD driver can only decode colors in integer or array format
- GD driver can only decode array color format array{red: int,
- Unable to decode binary data from empty string
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/67ecf1a1b7c7c346.
Report an issue: GitHub.