{"record":{"id":"b9a65da58a8fbda3","repo":"Intervention/image","slug":"invalid-cmyk-color-syntax-input","errorCode":null,"errorMessage":"Invalid cmyk() color syntax \"{input}\"","messagePattern":"Invalid cmyk\\(\\) color syntax \"(.+?)\"","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/Cmyk/Decoders/StringColorDecoder.php","lineNumber":48,"sourceCode":"            return false;\n        }\n\n        if (!str_starts_with(strtolower($input), 'cmyk')) {\n            return false;\n        }\n\n        return true;\n    }\n\n    /**\n     * Decode CMYK color strings\n     *\n     * @throws InvalidArgumentException\n     */\n    public function decode(mixed $input): ColorInterface\n    {\n        if (preg_match(self::PATTERN, (string) $input, $matches) !== 1) {\n            throw new InvalidArgumentException('Invalid cmyk() color syntax \"' . $input . '\"');\n        }\n\n        $values = array_map(function (string $value): int {\n            return intval(round(floatval(trim(str_replace('%', '', $value)))));\n        }, [$matches['c'], $matches['m'], $matches['y'], $matches['k']]);\n\n        return new Color(...$values);\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":58,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/Cmyk/Decoders/StringColorDecoder.php#L30-L58","documentation":"The CMYK string decoder only accepts strings matching 'cmyk(...)' with exactly four non-negative numeric components, each optionally suffixed with '%', separated by a comma (with optional space) or a single space: cmyk(100, 0, 0, 0) or cmyk(100%, 0%, 0%, 0%). Anything else that still begins with 'cmyk' - wrong component count, negative numbers, an alpha part, missing parenthesis - triggers this InvalidArgumentException.","triggerScenarios":"Cmyk\\Color::parse('cmyk(100, 0, 0)') (only 3 values); 'cmyk(100%, 0%, 0%, 0%, 0.5)' (alpha is not supported); 'cmyk(-10, 0, 0, 0)' (negative); 'cmyk(100,0,0,0' (missing ')'); 'cmyk(101%%, 0, 0, 0)' (malformed percent); smart quotes or non-ASCII dashes copied from design tools.","commonSituations":"Color strings copied from CSS/design software that append alpha ('/ 0.5' syntax), typo'd component counts in config files or CMS fields, user-supplied color input from forms passed straight to the decoder, or text editors auto-replacing hyphens/quotes with Unicode variants.","solutions":["Correct the string to four non-negative components: integers 0-100 or percentages, with no alpha part","Remove the alpha component - the decoder cannot parse it; apply alpha separately via Cmyk\\Color::create($c, $m, $y, $k, $alpha)","Normalize user input before parsing (trim, strip whitespace variants, replace Unicode punctuation)","If the value is dynamic, build programmatically: Cmyk\\Color::create(100, 0, 0, 0) instead of string parsing"],"exampleFix":"// before\n$color = Cmyk\\Color::parse('cmyk(100%, 0%, 0%, 0% / 0.5)');\n\n// after\n$color = Cmyk\\Color::parse('cmyk(100%, 0%, 0%, 0%)');\n$color = Cmyk\\Color::create(100, 0, 0, 0, 0.5); // needs alpha?","handlingStrategy":"validation","validationCode":"if (!preg_match('/^cmyk ?\\(([0-9.]+%?)(, ?| )([0-9.]+%?)(, ?| )([0-9.]+%?)(, ?| )([0-9.]+%?)\\)$/i', trim($input))) {\n    // reject before calling Cmyk\\Color::parse()\n    throw new InvalidArgumentException('Bad cmyk string: ' . $input);\n}","typeGuard":"function isCmykString(mixed $input): bool\n{\n    return is_string($input)\n        && str_starts_with(strtolower(trim($input)), 'cmyk(')\n        && substr_count($input, ',') + substr_count(trim($input), ' ') >= 3;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException as ImageArg;\n\ntry {\n    $color = Cmyk\\Color::parse($input);\n} catch (ImageArg $e) {\n    // invalid syntax; use a default or re-ask the user\n    $color = Cmyk\\Color::create(0, 0, 0, 100);\n}","preventionTips":["Validate cmyk strings at the form/API boundary with the regex above","Do not append alpha to cmyk() strings - pass it to Color::create() instead","Normalize Unicode punctuation in user input before parsing"],"tags":["php","intervention-image","color","cmyk","string-parsing","validation"],"backgroundTag":"color-string-parse-error","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}