{"record":{"id":"26e9fd4484340808","repo":"Intervention/image","slug":"failed-to-create-color-from-input-input","errorCode":null,"errorMessage":"Failed to create color from input \"{input}\"","messagePattern":"Failed to create color from input \"(.+?)\"","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/Rgb/NamedColor.php","lineNumber":171,"sourceCode":"    case TURQUOISE = 'turquoise';\n    case VIOLET = 'violet';\n    case WHEAT = 'wheat';\n    case WHITE = 'white';\n    case WHITESMOKE = 'whitesmoke';\n    case YELLOW = 'yellow';\n    case YELLOWGREEN = 'yellowgreen';\n\n    /**\n     * Create new named color.\n     *\n     * @throws InvalidArgumentException\n     */\n    public static function create(string $input): ColorInterface\n    {\n        try {\n            return self::from(strtolower($input));\n        } catch (TypeError | ValueError) {\n            throw new InvalidArgumentException('Failed to create color from input \"' . $input . '\"');\n        }\n    }\n\n    /**\n     * Create new named color or return null of creation fails.\n     */\n    public static function tryCreate(string $input): ?ColorInterface\n    {\n        try {\n            return self::from(strtolower($input));\n        } catch (Error) {\n            return null;\n        }\n    }\n\n    /**\n     * {@inheritdoc}\n     *","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/Rgb/NamedColor.php#L153-L189","documentation":"NamedColor::create() accepts only exact CSS color names backed by the NamedColor enum (about 140 values like 'red', 'aliceblue', 'navy'). The input is lowercased and passed to the enum's from(); an unknown value makes from() throw ValueError, which this method converts into an InvalidArgumentException echoing your input.","triggerScenarios":"NamedColor::create('redd') (typo), NamedColor::create('grey') (British spelling, not a case), NamedColor::create('#ff0000') (hex is not a named color), or any string not present in the NamedColor enum cases.","commonSituations":"User- or CMS-supplied color names; expecting the full CSS color parser (hex, rgb(), hsl()) from a named-color-only API; localized color names.","solutions":["Use an exact CSS named color (check the NamedColor enum cases for the accepted list)","For hex/rgb()/rgba() strings, do not use NamedColor::create; pass them to the driver's color decoding or build an Rgb\\Color directly","Validate the name first with NamedColor::tryFrom(strtolower($name)) and fall back to a default color"],"exampleFix":"// before\n$color = NamedColor::create($userColor);\n\n// after\n$color = NamedColor::tryFrom(strtolower($userColor))\n    ? NamedColor::create($userColor)\n    : NamedColor::create('white');","handlingStrategy":"type-guard","validationCode":"$name = strtolower(trim($name));\nif (NamedColor::tryFrom($name) === null) {\n    $name = 'white';\n}","typeGuard":"function isNamedColor(string $value): bool\n{\n    return NamedColor::tryFrom(strtolower($value)) !== null;\n}","tryCatchPattern":"try {\n    $color = NamedColor::create($input);\n} catch (\\Intervention\\Image\\Exceptions\\InvalidArgumentException $e) {\n    $color = NamedColor::create('white');\n}","preventionTips":["Treat the NamedColor enum cases as the source of truth for accepted names","Lowercase and trim user input before matching","Route non-named formats (hex, rgb()) through the driver's color decoding instead"],"tags":["color","named-color","css","validation"],"backgroundTag":"unknown-color-name","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}