{"record":{"id":"d54e34f35ba70714","repo":"Intervention/image","slug":"unknown-color-format","errorCode":null,"errorMessage":"Unknown color format","messagePattern":"Unknown color format","errorType":"exception","errorClass":"ColorDecoderException","httpStatus":null,"severity":"error","filePath":"src/Drivers/AbstractDriver.php","lineNumber":96,"sourceCode":"     *\n     * @see DriverInterface::decodeColor()\n     *\n     * @throws InvalidArgumentException\n     * @throws ColorDecoderException\n     * @throws DriverException\n     */\n    public function decodeColor(mixed $input, ?array $decoders = null): ColorInterface\n    {\n        $decoders = $decoders === null ? InputHandler::COLOR_DECODERS : $decoders;\n\n        if (count($decoders) === 0) {\n            throw new InvalidArgumentException('No decoders in array');\n        }\n\n        try {\n            $result = InputHandler::usingDecoders($decoders, $this)->handle($input);\n        } catch (NotSupportedException) {\n            throw new ColorDecoderException('Unknown color format');\n        }\n\n        if (!$result instanceof ColorInterface) {\n            throw new ColorDecoderException('Result must be instance of ' . ColorInterface::class);\n        }\n\n        return $result;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see DriverInterface::specializeModifier()\n     *\n     * @throws NotSupportedException\n     */\n    public function specializeModifier(ModifierInterface $modifier): ModifierInterface\n    {","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/AbstractDriver.php#L78-L114","documentation":"The driver ran the full color decoder chain (hex strings, rgb()/rgba() strings, integer color values, named colors, 'transparent', and ColorInterface objects) and none could decode the input. The NotSupportedException from the chain is converted into this ColorDecoderException, so any color in a format the library does not speak produces it.","triggerScenarios":"fill('cmyk(0, 84, 100, 0)'), ->color('hsl(120, 50%, 50%)'), a misspelled name like 'rd', null, or a float like 12.5 passed to any color-accepting API (fill(), textColor(), backgroundColor, pickColor consumers).","commonSituations":"User- or CMS-entered colors with typos; CSS color functions the library does not support (hsl(), cmyk(), color()); values that are null because an upstream lookup failed.","solutions":["Convert the color to a supported format first - hex ('#ff0000') or rgb()/rgba() syntax - or use NamedColor/transparent","Validate user-provided colors at the input boundary and substitute a default when they do not match a supported format","If you need HSL/CMYK input, convert it to RGB yourself before passing it to the library"],"exampleFix":"// before\n$img->fill($userColor); // e.g. 'hsl(120, 50%, 50%)'\n\n// after\n$safe = validate_color($userColor) ?: '#ffffff';\n$img->fill($safe);","handlingStrategy":"try-catch","validationCode":"function isSupportedColorString(string $value): bool\n{\n    return preg_match('/^(#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})|rgba?\\(.+\\)|transparent|[a-z]+)$/i', $value) === 1;\n}","typeGuard":null,"tryCatchPattern":"try {\n    $img->fill($userColor);\n} catch (ColorDecoderException $e) {\n    $img->fill('#ffffff');\n}","preventionTips":["Convert hsl()/cmyk() input to hex or rgb() before passing","Default user-supplied colors to a known-safe fallback","Catch ColorDecoderException at the input boundary, not deep in image pipelines"],"tags":["color","decoder","input-validation","unsupported-format"],"backgroundTag":"unknown-color-format","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}