Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException
Unable to parse OKLAB color from input "{input}"
Error message
Unable to parse OKLAB color from input "{input}" What it means
Oklab\Color::parse() pushes the input through an InputHandler configured with only the OKLAB StringColorDecoder; if that pipeline reports it cannot process the input (NotSupportedException) or a decoder cannot be resolved (DriverException), the failure is rethrown as this InvalidArgumentException (src/Colors/Oklab/Color.php:57-68). Note that a well-formed-but-malformed 'oklab(...)' string instead surfaces the more specific 'Invalid oklab() color syntax' error from the decoder itself.
Source
Thrown at src/Colors/Oklab/Color.php:64
public static function create(float|Lightness $l, float|A $a, float|B $b, float|Alpha $alpha = 1): self
{
return new self($l, $a, $b, $alpha);
}
/**
* Parse OKLAB 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 OKLAB 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 oklab(...) string format: 'oklab(0.5, 0.1, 0.1)' or 'oklab(50% 0.1 0.1 / 0.5)'
- For other formats, parse with the generic driver color pipeline or the matching colorspace's Color::parse() first, then convert with toColorspace()
- For programmatic values, construct directly: Oklab\Color::create(0.5, 0.1, 0.1)
- Catch InvalidArgumentException around parse() when input is user-supplied
Example fix
// before
$color = Oklab\Color::parse('#ff5500'); // not an oklab() string
// after
$color = Rgb\Color::parse('#ff5500')->toColorspace(Oklab\Colorspace::class);
// or construct directly:
$color = Oklab\Color::create(0.5, 0.1, 0.1); Defensive patterns
Strategy: validation
Validate before calling
if (!is_string($input) || !preg_match('/^oklab\s*\(/i', $input)) {
// route to a generic parser or reject before calling Oklab\Color::parse()
} Type guard
function looksLikeOklabString(mixed $input): bool
{
return is_string($input) && str_starts_with(strtolower($input), 'oklab');
} Try / catch
try {
$color = Oklab\Color::parse($input);
} catch (Intervention\Image\Exceptions\InvalidArgumentException $e) {
// input was not consumable as oklab(); try generic pipeline or reject
} Prevention
- Match the parser to the format: only pass oklab(...) strings to Oklab\Color::parse()
- For arbitrary color strings, use the driver's generic color decoding and then toColorspace()
- Construct Oklab\Color::create() directly when you already hold numeric channels
When it happens
Trigger: Calling Oklab\Color::parse() with input the registered decoder chain rejects (e.g. a hex string, a color name, or a non-'oklab(...)' format reaching the handler path that throws NotSupportedException 'Unprocessable input').
Common situations: Passing '#ff5500', 'red' or an 'hsl(...)' string to the OKLAB-specific parse() instead of the generic color parser; assuming parse() accepts any color format rather than only oklab() strings.
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
- 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}
- Invalid oklab() color syntax "{input}"
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/3cfab7a3efb4118d.
Report an issue: GitHub.