Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException
Percentage value must be between -100 and 100
Error message
Percentage value must be between -100 and 100
What it means
When the colorspace target is a string that is not a class name, ColorspaceModifier matches it against the supported list: rgb/srgb/rgba/srgba, cmyk, hsl, hsv/hsb, oklab, oklch. Anything else — including differently-cased strings, since the match is case-sensitive — throws NotSupportedException with the terse 'Colorspace is not supported by driver'.
Source
Thrown at src/Colors/AbstractColorChannel.php:42
{
return round(($this->value() - $this->min()) / ($this->max() - $this->min()), $precision);
}
/**
* {@inheritdoc}
*
* @see ColorChannelInterface::scale()
*
* @throws InvalidArgumentException
*/
public function scale(int $percent): self
{
if ($percent === 0) {
return $this;
}
if ($percent < -100 || $percent > 100) {
throw new InvalidArgumentException('Percentage value must be between -100 and 100');
}
$normalized = $this->normalized();
$base = $percent >= 0 ? (1 - $normalized) : $normalized;
$scaled = min(1.0, max(0.0, $normalized + $base / 100 * $percent));
$this->value = static::fromNormalized($scaled)->value();
return $this;
}
/**
* Throw exception if the given value is not applicable for channel
* otherwise the value is returned unchanged.
*
* @throws InvalidArgumentException
*/
protected function validValueOrFail(int|float $value): mixed
{View on GitHub (pinned to 5598b9e397)
Solutions
- Use lowercase canonical strings: 'rgb', 'cmyk', 'hsl', 'hsv', 'oklab', 'oklch', or pass Colorspace class names like Rgb::class.
- Normalize user input: $target = strtolower(trim($target)) before calling ->colorspace($target).
- Map exotic names yourself ('greyscale' => 'rgb') instead of forwarding them.
- Catch NotSupportedException to give a helpful message listing valid values.
Example fix
// before
$image->colorspace($request->string('colorspace')); // 'CMYK' throws
// after
$target = strtolower(trim($request->string('colorspace')));
$image->colorspace(match (true) {
str_starts_with($target, 'cmyk') => 'cmyk',
default => 'rgb',
}); Defensive patterns
Strategy: validation
Validate before calling
$target = strtolower(trim($target));
$valid = ['rgb', 'srgb', 'rgba', 'srgba', 'cmyk', 'hsl', 'hsv', 'hsb', 'oklab', 'oklch'];
if (!in_array($target, $valid, true)) {
throw new InvalidArgumentException('Unknown colorspace: ' . $target);
}
$image->colorspace($target); Try / catch
try {
$image->colorspace($target);
} catch (Intervention\Image\Exceptions\NotSupportedException $e) {
// default to 'rgb' and warn
} Prevention
- Lowercase and trim any string before ->colorspace().
- Map domain names ('greyscale', 'CMYK') to supported values yourself.
- Note the match is case-sensitive: only lowercase strings are accepted.
When it happens
Trigger: $image->colorspace('CMYK') (uppercase), $image->colorspace('gray'), $image->colorspace('s-RGB'), or any misspelling; values arriving from user input or config files unnormalized.
Common situations: Uppercase values from print-industry tooling; 'gray'/'greyscale' expectations carried over from other libraries (ImageMagick names); config keys written by hand.
Related errors
- Failed to invert color
- Color channel {class} value must be in range {min} to {max}
- Unable to parse CMYK color from input "{input}"
- Unable to import color {colorClass} to {class}
- Unable to parse OKLAB color from input "{input}"
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/f0a3f50b2798af02.
Report an issue: GitHub.