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(): ColorspaceInterface

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Use the oklab(...) string format: 'oklab(0.5, 0.1, 0.1)' or 'oklab(50% 0.1 0.1 / 0.5)'
  2. For other formats, parse with the generic driver color pipeline or the matching colorspace's Color::parse() first, then convert with toColorspace()
  3. For programmatic values, construct directly: Oklab\Color::create(0.5, 0.1, 0.1)
  4. 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

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

Related errors


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/3cfab7a3efb4118d. Report an issue: GitHub.