{"record":{"id":"d2532e2c41013bc0","repo":"Intervention/image","slug":"unable-to-parse-rgb-color-from-input-input-d2532e","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/Colors/Rgb/Color.php","lineNumber":67,"sourceCode":"        return new self($r, $g, $b, $a);\n    }\n\n    /**\n     * Parse RGB color from string.\n     *\n     * @throws InvalidArgumentException\n     * @throws ColorException\n     */\n    public static function parse(string $input): self\n    {\n        try {\n            $color = InputHandler::usingDecoders([\n                StringColorDecoder::class,\n                NamedColorDecoder::class,\n                HexColorDecoder::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 self) {\n            throw new ColorException('Result must be instance of ' . self::class);\n        }\n\n        return $color;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ColorInterface::colorspace()\n     */\n    public function colorspace(): ColorspaceInterface","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/Rgb/Color.php#L49-L85","documentation":"Rgb\\Color::parse() runs the input through three decoders (rgb() strings, named CSS colors, hex strings). This wrapped error appears when no decoder even claims the input, i.e. the InputHandler throws NotSupportedException ('Unprocessable input') or a DriverException; the original exception is chained and readable via $e->getPrevious(). Note the distinction: input that looks like an rgb() string or hex but has bad syntax makes the decoder itself throw its own InvalidArgumentException, which propagates unwrapped.","triggerScenarios":"Rgb\\Color::parse('xyz'), parse('hsl(0, 50%, 50%)') (the RGB parser only handles rgb()/named/hex), parse('12,34,56') or any free-form string matched by no decoder's supports().","commonSituations":"Parsing user-supplied color values from forms, spreadsheets or CMS fields; assuming the RGB parser accepts every CSS color format (hsl(), cmyk(), oklch() each have their own parse methods); migrating from v2 where color creation accepted looser input.","solutions":["Feed a supported format: 'rgb(255 0 0)', a named color like 'tomato', or hex like '#ff0000'","For other colorspaces, parse with the matching class then convert, e.g. Hsl\\Color::parse('hsl(0, 100%, 50%)')->toColorspace(Rgb\\Colorspace::class)","Inspect $e->getPrevious() to find which stage rejected the input","Validate free-form input against the expected formats before calling parse()"],"exampleFix":"// before\n$color = \\Intervention\\Image\\Colors\\Rgb\\Color::parse('hsl(0, 100%, 50%)');\n\n// after\n$color = \\Intervention\\Image\\Colors\\Hsl\\Color::parse('hsl(0, 100%, 50%)')\n    ->toColorspace(\\Intervention\\Image\\Colors\\Rgb\\Colorspace::class);","handlingStrategy":"try-catch","validationCode":"$ok = is_string($input)\n    && (\n        preg_match('/^s?rgba?\\s*\\(/i', $input) === 1\n        || preg_match('/^#?([a-f\\d]{3}|[a-f\\d]{4}|[a-f\\d]{6}|[a-f\\d]{8})$/i', $input) === 1\n        || \\Intervention\\Image\\Colors\\Rgb\\Decoders\\NamedColorDecoder::class !== null // named colors: consult CSS name list\n    );\nif (!$ok) {\n    throw new \\RuntimeException('Unsupported color format');\n}","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\nuse Intervention\\Image\\Exceptions\\ColorException;\n\ntry {\n    $color = \\Intervention\\Image\\Colors\\Rgb\\Color::parse($input);\n} catch (InvalidArgumentException | ColorException $e) {\n    $color = \\Intervention\\Image\\Colors\\Rgb\\Color::create(0, 0, 0); // or report validation error\n}","preventionTips":["Restrict accepted input to rgb()/rgba() strings, named CSS colors or 3/4/6/8-digit hex","Parse hsl/cmyk/oklch values with their dedicated Color::parse() methods, then convert","Check $e->getPrevious() to learn which decoder stage rejected the input"],"tags":["rgb","color-parsing","php","intervention-image"],"backgroundTag":"color-parse-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}