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(): ColorspaceInterfaceView on GitHub (pinned to 5598b9e397)
Solutions
- Skip the call for non-positive sizes: if ($size >= 1) { $image->pixelate($size); }.
- Clamp user input: max(1, (int) $size).
- 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
- Treat 0 as 'skip the effect', not as an argument.
- Clamp user 'intensity' values to >= 1.
- Cast to int: the parameter is typed and floats in strict mode are rejected.
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
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to invert color
- Color channel {class} value must be in range {min} to {max}
- Percentage value must be between -100 and 100
- Color channel value of {class} must be in range 0 to 1
- Number of color channels must be 4 or 5 for {class}
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/054a3c5d2a4e9de9.
Report an issue: GitHub.