{"record":{"id":"4479dc962c3643df","repo":"Intervention/image","slug":"unknown-color-space-colorspace-as-conversion-t","errorCode":null,"errorMessage":"Unknown color space ({colorspace}) as conversion target","messagePattern":"Unknown color space \\((.+?)\\) as conversion target","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/AbstractColor.php","lineNumber":73,"sourceCode":"\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\n        $colorspace = is_string($colorspace) ? new $colorspace() : $colorspace;\n\n        if (!$colorspace instanceof ColorspaceInterface) {\n            throw new InvalidArgumentException('Given color space must implement ' . ColorspaceInterface::class);\n        }\n\n        return $colorspace->importColor($this);\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ColorInterface::isTransparent()\n     */\n    public function isTransparent(): bool\n    {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/AbstractColor.php#L55-L91","documentation":"Font::setAlignmentVertical() is the vertical counterpart: strings must exactly match an Alignment enum backing value ('top', 'center', 'bottom', or the diagonals like 'top-left'); everything else makes Alignment::from() throw, which the setter converts into InvalidArgumentException('Invalid value for alignment'). It is reached through FontFactory::align(null, $vertical) or direct font configuration.","triggerScenarios":"$font->align(null, 'middle') or 'baseline' (not enum values); 'TOP' or 'Top' with wrong casing; underscore forms like 'bottom_center'; vertical values coming from a UI dropdown that uses different vocabulary ('top-edge', 'flow-root').","commonSituations":"CSS vertical-align vocabulary ('middle', 'baseline', 'sub') reused for image text; snake_case values from JavaScript front-ends; localized strings; config files written before the exact allowed set was known.","solutions":["Use the exact lowercase values: 'top', 'center', 'bottom' (or diagonal cases if combined)","Sanitize external input: strtolower() + str_replace(['_', ' '], '-', $value), and whitelist against ['top', 'center', 'bottom']","Pass Alignment::TOP / Alignment::CENTER / Alignment::BOTTOM enum instances to avoid string pitfalls entirely"],"exampleFix":"// before\n$font->align(null, 'MIDDLE'); // case-sensitive from() -> throws\n\n// after\n$font->align(null, 'middle'); // or Alignment::MIDDLE does not exist; use:\n$font->align(null, \\Intervention\\Image\\Alignment::CENTER);","handlingStrategy":"type-guard","validationCode":"use Intervention\\Image\\Alignment;\n\n$value = strtolower(trim((string) $input));\nif (!in_array($value, ['top', 'center', 'bottom'], true)) {\n    $value = 'center'; // or reject\n}\n$font->align(null, $value);","typeGuard":"use Intervention\\Image\\Alignment;\n\nfunction toVerticalAlignment(string $value): Alignment\n{\n    return match (strtolower($value)) {\n        'top' => Alignment::TOP,\n        'bottom' => Alignment::BOTTOM,\n        'center', 'middle' => Alignment::CENTER,\n        default => throw new \\InvalidArgumentException('Invalid vertical alignment: ' . $value),\n    };\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $font->align(null, $vertical);\n} catch (InvalidArgumentException $e) {\n    if (str_contains($e->getMessage(), 'alignment')) {\n        $font->align(null, 'center'); // safe default\n    }\n}","preventionTips":["Map CSS-style vocabulary ('middle', 'baseline') to the library's 'top'/'center'/'bottom' in your own adapter","Constrain vertical alignment dropdowns/config keys to the three supported words","Same string rules as horizontal alignment: exact lowercase backing values only"],"tags":["typography","font","vertical-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"}