{"record":{"id":"47cb13738aae42f5","repo":"Intervention/image","slug":"unable-to-parse-rgb-color-from-input-input","errorCode":null,"errorMessage":"Unable to parse RGB color from input \"{input}\"","messagePattern":"Unable to parse RGB color from input \"(.+?)\"","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Color.php","lineNumber":73,"sourceCode":"     *\n     * @throws InvalidArgumentException\n     * @throws ColorException\n     */\n    public static function parse(string $input): ColorInterface\n    {\n        try {\n            $color = InputHandler::usingDecoders([\n                RgbStringColorDecoder::class,\n                CmykStringColorDecoder::class,\n                HsvStringColorDecoder::class,\n                HslStringColorDecoder::class,\n                OklabStringColorDecoder::class,\n                OklchStringColorDecoder::class,\n                NamedColorDecoder::class,\n                RgbHexColorDecoder::class,\n            ])->handle($input);\n        } catch (NotSupportedException | DriverException $e) {\n            throw new InvalidArgumentException(\n                'Unable to parse RGB color from input \"' . $input . '\"',\n                previous: $e,\n            );\n        }\n\n        if (!$color instanceof ColorInterface) {\n            throw new ColorException('Result must be instance of ' . self::class . ', got ' . $color::class);\n        }\n\n        return $color;\n    }\n\n    /**\n     * Create new RGB color.\n     *\n     * @throws InvalidArgumentException\n     * @throws DriverException\n     */","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Color.php#L55-L91","documentation":"Font::setStrokeWidth() validates that the text stroke width is an integer between 0 and 10 (in_array($width, range(0, 10))). Values outside that range — negative numbers or anything above 10 — throw this InvalidArgumentException. You reach it through the typography API, e.g. ->stroke($color, $width) when drawing text or configuring a font via FontFactory.","triggerScenarios":"$font->stroke('fff', 12) or a negative width like -1; ->strokeWidth(15) on a font; computing the width from a percentage of image size (e.g. intval($image->width() / 100)) without clamping, which exceeds 10 for wide images; copying a CSS text-shadow spread value (often 20+) into the stroke width.","commonSituations":"Dynamic stroke widths derived from image dimensions or font size that accidentally scale past 10; designers requesting thicker outlines than the library allows; porting code from a tool with unbounded stroke widths; unit tests asserting out-of-range values throw.","solutions":["Clamp the value before passing it: $width = max(0, min(10, $width))","Validate user/designer input against the 0-10 range in your form/config layer","If you truly need a thicker outline, layer it: draw the text multiple times with small offsets at width 10, or pre-render with another tool"],"exampleFix":"// before\n$font->stroke('ff0000', $dynamicWidth); // throws when $dynamicWidth > 10\n\n// after\n$font->stroke('ff0000', max(0, min(10, (int) $dynamicWidth)));","handlingStrategy":"validation","validationCode":"$width = (int) $requestedWidth;\nif ($width < 0 || $width > 10) {\n    $width = max(0, min(10, $width)); // clamp, or reject:\n    // throw new \\InvalidArgumentException('Stroke width must be 0-10');\n}\n$font->strokeWidth($width);","typeGuard":"function isValidStrokeWidth(mixed $width): bool\n{\n    return is_int($width) && $width >= 0 && $width <= 10;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $font->stroke($color, $dynamic);\n} catch (InvalidArgumentException $e) {\n    if (str_contains($e->getMessage(), 'stroke width')) {\n        $font->stroke($color, 10); // degrade to maximum allowed stroke\n    }\n}","preventionTips":["Clamp any computed stroke width (from image size, font size, percentages) to 0-10 at the source","Validate designer/user inputs for stroke width with a 0-10 rule in the form layer","Remember the parameter is int: pass ints, not floats, since strict_types will reject 1.5 before the range check"],"tags":["typography","font","stroke","out-of-range","validation","intervention-image"],"backgroundTag":"value-out-of-range","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}