Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException
Color channel {class} value must be in range {min} to {max}
Error message
Color channel {class} value must be in range {min} to {max} What it means
DrawPolygonModifier requires the Polygon it receives to contain at least 3 points, because a polygon with fewer vertices cannot be rasterized. The check runs in the constructor, so $image->drawPolygon() fails immediately when handed a degenerate Polygon.
Source
Thrown at src/Colors/AbstractColorChannel.php:62
$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
{
if ($value < $this->min() || $value > $this->max()) {
throw new InvalidArgumentException(
'Color channel ' . $this::class . ' value must be in range ' . $this->min() . ' to ' . $this->max(),
);
}
return $value;
}
/**
* {@inheritdoc}
*
* @see ColorChannelInterface::toString()
*/
public function toString(): string
{
return (string) $this->value();
}
/**View on GitHub (pinned to 5598b9e397)
Solutions
- Count before drawing: if ($polygon->count() >= 3) { $image->drawPolygon($polygon); }.
- Skip or log degenerate datasets instead of drawing them.
- If points were removed by validation, treat fewer than 3 remaining points as 'nothing to draw', not as a draw call.
Example fix
// before
$image->drawPolygon($polygon); // count() === 2 throws
// after
if ($polygon->count() >= 3) {
$image->drawPolygon($polygon);
} Defensive patterns
Strategy: validation
Validate before calling
if ($polygon->count() < 3) {
// nothing drawable; skip or log
return;
}
$image->drawPolygon($polygon); Type guard
function isDrawablePolygon(Intervention\Image\Geometry\Polygon $polygon): bool
{
return $polygon->count() >= 3;
} Prevention
- Check count() >= 3 whenever points come from filtering or external data.
- Treat degenerate geometry as a no-op in renderers.
- Guard the data source: require at least 3 coordinate rows before building the Polygon.
When it happens
Trigger: $image->drawPolygon(new Polygon($points)) where $points has 0-2 entries; building points dynamically from data that can collapse (filtered results, empty datasets, division producing coincident points reduced by dedup).
Common situations: Chart/map overlays where a region's coordinates come from a database query that returned one row; array_filter() removing invalid points below the threshold; empty input arrays from failed upstream parsing.
Related errors
- Failed to invert color
- Unable to parse CMYK color from input "{input}"
- Failed to apply Intervention\Image\Drivers\Imagick\Modifiers
- Percentage value must be between -100 and 100
- Color channel value of {class} must be in range 0 to 1
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/18c1cc7e50ec462c.
Report an issue: GitHub.