{"record":{"id":"e0f861f8c8061ff1","repo":"Intervention/image","slug":"color-channel-classname-could-not-be-found","errorCode":null,"errorMessage":"Color channel {classname} could not be found","messagePattern":"Color channel (.+?) could not be found","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/AbstractColor.php","lineNumber":57,"sourceCode":"        return $this->channels;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ColorInterface::channel()\n     *\n     * @throws InvalidArgumentException\n     */\n    public function channel(string $classname): ColorChannelInterface\n    {\n        $channels = array_filter(\n            $this->channels(),\n            fn(ColorChannelInterface $channel): bool => $channel::class === $classname,\n        );\n\n        if (count($channels) === 0) {\n            throw new InvalidArgumentException('Color channel ' . $classname . ' could not be found');\n        }\n\n        return reset($channels);\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ColorInterface::toColorspace()\n     *\n     * @throws InvalidArgumentException\n     */\n    public function toColorspace(string|ColorspaceInterface $colorspace): ColorInterface\n    {\n        if (is_string($colorspace) && !class_exists($colorspace)) {\n            throw new InvalidArgumentException('Unknown color space (' . $colorspace . ') as conversion target');\n        }\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/AbstractColor.php#L39-L75","documentation":"Font::setAlignmentHorizontal() accepts a string or an Alignment enum. Strings are converted with Alignment::from(), which is an exact, case-sensitive match against the nine enum backing values ('top', 'top-right', 'right', 'bottom-right', 'bottom', 'bottom-left', 'left', 'top-left', 'center'). Any other string — including alias forms that Alignment::create() would accept, like 'center-left' or 'top_left' — raises a ValueError that the setter rethrows as InvalidArgumentException('Invalid value for alignment'). You hit it via FontFactory::align($horizontal, $vertical) or the text API's alignment option.","triggerScenarios":"$font->align('center-left'), 'top_left', 'Center' (capitalized), 'middle', 'centre' or any custom string; feeding alignment from user input or a config file without validating it; values built by string concatenation ('top' . '-' . 'center').","commonSituations":"Front-end or API alignment values in snake_case or with mixed case; reusing values that worked with the position/Alignment::create() alias table elsewhere in the library; i18n/localized alignment names ('centro', 'Mitte') passed straight through.","solutions":["Use one of the nine exact lowercase values: 'left', 'center', 'right' (pure horizontal), or the diagonal forms like 'top-left'","Normalize input before passing: $value = strtolower(str_replace('_', '-', $userValue)) and map aliases yourself, or call Alignment::create($value) which understands the alias table, and pass the resulting enum","Pass an Alignment enum instance instead of a string to get static type safety"],"exampleFix":"// before\n$font->align('center_left'); // not a backing value -> throws\n\n// after\nuse Intervention\\Image\\Alignment;\n$font->align(Alignment::create('center_left')); // alias-aware, returns Alignment::LEFT\n// or simply: $font->align('left');","handlingStrategy":"type-guard","validationCode":"use Intervention\\Image\\Alignment;\n\n$alignment = Alignment::tryFrom(strtolower((string) $input));\nif ($alignment === null) {\n    $alignment = Alignment::tryCreate((string) $input) // alias-aware fallback\n        ?? throw new \\InvalidArgumentException('Unsupported alignment: ' . $input);\n}\n$font->align($alignment);","typeGuard":"use Intervention\\Image\\Alignment;\n\nfunction toHorizontalAlignment(string $value): Alignment\n{\n    return Alignment::tryFrom(strtolower($value))\n        ?? Alignment::tryCreate($value)\n        ?? throw new \\InvalidArgumentException('Invalid horizontal alignment: ' . $value);\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $font->align($userValue);\n} catch (InvalidArgumentException $e) {\n    if (str_contains($e->getMessage(), 'alignment')) {\n        $font->align('center'); // safe default\n    }\n}","preventionTips":["Whitelist horizontal values at the boundary: ['left', 'center', 'right'] (plus diagonal enum cases when needed)","Normalize external strings: lowercase, underscores/dashes unified, before they reach the font API","Prefer passing Alignment enum instances over strings in internal code"],"tags":["typography","font","alignment","enum","invalid-argument","intervention-image"],"backgroundTag":"invalid-enum-value","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}