{"record":{"id":"67ecf1a1b7c7c346","repo":"Intervention/image","slug":"you-must-specify-either-3-or-4-points-to-create-a","errorCode":null,"errorMessage":"You must specify either 3 or 4 points to create a bezier curve","messagePattern":"You must specify either 3 or 4 points to create a bezier curve","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Modifiers/DrawBezierModifier.php","lineNumber":62,"sourceCode":"\n            if ($this->drawable->hasBorder() && $this->drawable->borderSize() > 0) {\n                $borderColor = $this->driver()->colorProcessor($image)->export($this->borderColor());\n                $this->drawBezierBorder($frame->native(), $polygon, $polygonBorderSegments, $borderColor);\n            }\n        }\n\n        return $image;\n    }\n\n    /**\n     * Validate that the drawable has exactly 3 or 4 points.\n     *\n     * @throws InvalidArgumentException\n     */\n    private function validatePointCount(): void\n    {\n        if ($this->drawable->count() !== 3 && $this->drawable->count() !== 4) {\n            throw new InvalidArgumentException('You must specify either 3 or 4 points to create a bezier curve');\n        }\n    }\n\n    /**\n     * Draw the bezier polygon with the background color.\n     *\n     * @param array<mixed> $polygon\n     * @throws ModifierException\n     */\n    private function drawBezierBackground(GdImage $canvas, array $polygon, int $color): void\n    {\n        imagesetthickness($canvas, 0);\n        $this->abortUnless(imagefilledpolygon($canvas, $polygon, $color), 'Unable to draw bezier background');\n    }\n\n    /**\n     * Draw the bezier border, using thin lines for size 1 or filled polygon segments otherwise\n     *","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Modifiers/DrawBezierModifier.php#L44-L80","documentation":"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.","triggerScenarios":"$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.","commonSituations":"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().","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)"],"exampleFix":"// before: two points do not define a curve\n$image->drawBezier(fn($b) => $b->point(0, 100)->point(100, 100));\n\n// after: three points define a quadratic bezier\n$image->drawBezier(fn($b) => $b\n    ->point(0, 100)\n    ->point(50, 0)\n    ->point(100, 100));","handlingStrategy":"validation","validationCode":"use Intervention\\Image\\Geometry\\Bezier;\nuse Intervention\\Image\\Geometry\\Point;\n\n$bezier = new Bezier();\n$bezier->addPoint(new Point(0, 100));\n$bezier->addPoint(new Point(50, 0));\n$bezier->addPoint(new Point(100, 100));\n\nif (!in_array($bezier->count(), [3, 4], true)) {\n    throw new InvalidArgumentException(\n        'Bezier needs exactly 3 or 4 points, got ' . $bezier->count()\n    );\n}\n\n$image->drawBezier($bezier);","typeGuard":"use Intervention\\Image\\Geometry\\Bezier;\n\nfunction isDrawableBezier(Bezier $bezier): bool\n{\n    return in_array($bezier->count(), [3, 4], true);\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $image->drawBezier($bezier);\n} catch (InvalidArgumentException $e) {\n    // fix the point list, or draw a polygon with the same points instead\n    $image->drawPolygon($bezier);\n}","preventionTips":["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."],"tags":["gd","bezier","drawing","points","validation","invalid-argument"],"backgroundTag":"invalid-argument-count","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}