Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException
Unable to parse OKLCH color from input "{input}"
Error message
Unable to parse OKLCH color from input "{input}" What it means
Oklch\Color::parse() runs the input through an InputHandler registered with only the OKLCH StringColorDecoder; when that pipeline reports it cannot process the input (NotSupportedException) or the decoder cannot be resolved (DriverException), it is rethrown as this InvalidArgumentException (src/Colors/Oklch/Color.php:57-68). A malformed-but-prefixed 'oklch(...)' string instead surfaces the decoder's own 'Invalid oklch() color syntax' error.
Source
Thrown at src/Colors/Oklch/Color.php:64
public static function create(float|Lightness $l, float|Chroma $c, float|Hue $h, float|Alpha $a = 1): self
{
return new self($l, $c, $h, $a);
}
/**
* Parse OKLCH color from string.
*
* @throws InvalidArgumentException
* @throws ColorException
*/
public static function parse(string $input): self
{
try {
$color = InputHandler::usingDecoders([
StringColorDecoder::class,
])->handle($input);
} catch (NotSupportedException | DriverException $e) {
throw new InvalidArgumentException(
'Unable to parse OKLCH color from input "' . $input . '"',
previous: $e,
);
}
if (!$color instanceof self) {
throw new ColorException('Result must be instance of ' . self::class);
}
return $color;
}
/**
* {@inheritdoc}
*
* @see ColorInterface::colorspace()
*/
public function colorspace(): ColorspaceInterfaceView on GitHub (pinned to 5598b9e397)
Solutions
- Use the oklch(...) string format: 'oklch(0.5, 0.1, 150)'
- For other formats, parse with the matching Color::parse() or the generic pipeline and convert with toColorspace()
- Construct directly with Oklch\Color::create(l, c, h)
- Wrap parse() in try/catch InvalidArgumentException when input is external
Example fix
// before
$color = Oklch\Color::parse('rgb(255, 85, 0)'); // not an oklch() string
// after
$color = Rgb\Color::parse('rgb(255, 85, 0)')->toColorspace(Oklch\Colorspace::class);
// or construct directly:
$color = Oklch\Color::create(0.65, 0.2, 30); Defensive patterns
Strategy: validation
Validate before calling
if (!is_string($input) || !preg_match('/^oklch\s*\(/i', $input)) {
// do not call Oklch\Color::parse(); use a generic parser and convert
} Type guard
function looksLikeOklchString(mixed $input): bool
{
return is_string($input) && str_starts_with(strtolower($input), 'oklch');
} Try / catch
try {
$color = Oklch\Color::parse($input);
} catch (Intervention\Image\Exceptions\InvalidArgumentException $e) {
// input not consumable as oklch(); fall back to generic decoding or reject
} Prevention
- Only feed oklch(...) strings to the OKLCH-specific parser
- Convert from other formats via their own parse() plus toColorspace()
- Use Oklch\Color::create() when numeric channels are already available
When it happens
Trigger: Calling Oklch\Color::parse() with input the oklch decoder chain rejects, e.g. a hex string, color name, or any non-'oklch(...)' color format pushed through the OKLCH-specific parser.
Common situations: Passing '#ff5500' or 'red' to the OKLCH-specific parse() instead of a generic parser; assuming one parse() accepts every color format.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Unable to parse OKLAB color from input "{input}"
- Number of color channels must be 3 or 4 for {class}
- Normalized color value must be in range 0 to 1
- Unable to import color {color_class} to {colorspace_class}
- Failed to import color {color_class} to {colorspace_class}
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/8d1f1a410873efa0.
Report an issue: GitHub.