Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException

Unable to parse CMYK color from input "{input}"

Error message

Unable to parse CMYK color from input "{input}"

What it means

PixelateModifier's constructor requires a pixelation size of at least 1, because a zero or negative block size cannot produce a pixelation effect. The int type hint already rejects non-integers; this guard rejects the remaining invalid range.

Source

Thrown at src/Colors/Cmyk/Color.php:66

    public static function create(int|Cyan $c, int|Magenta $m, int|Yellow $y, int|Key $k, float|Alpha $a = 1): self
    {
        return new self($c, $m, $y, $k, $a);
    }

    /**
     * Parse CMYK 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 CMYK 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. Skip the call for non-positive sizes: if ($size >= 1) { $image->pixelate($size); }.
  2. Clamp user input: max(1, (int) $size).
  3. In your wrapper, make 0 mean 'skip effect' explicitly instead of passing it through.

Example fix

// before
$image->pixelate($request->integer('size')); // 0 throws

// after
$size = max(1, $request->integer('size'));
$image->pixelate($size);
Defensive patterns

Strategy: validation

Validate before calling

$size = max(1, (int) $size);
$image->pixelate($size);

Prevention

When it happens

Trigger: $image->pixelate(0); $image->pixelate(-10); computing size from a user 'intensity' parameter that can be zero or negative.

Common situations: Treating 0 as 'no pixelation' and forwarding it anyway; inverting a scale where higher = finer so pixel size ends up <= 0; default parameter set to 0 in a wrapper function.

Understand the failure class

Related errors


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