Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException
Normalized color value must be in range 0 to 1
Error message
Normalized color value must be in range 0 to 1
What it means
RemoveAnimationModifier keeps one frame of an animated image and selects it by $position. Integer positions must be non-negative frame indexes; a negative int throws InvalidArgumentException in the constructor before anything is applied. (String positions follow a different, percent-based path.)
Source
Thrown at src/Colors/Cmyk/Colorspace.php:57
* @see ColorspaceInterface::colorFromNormalized()
*
* @throws InvalidArgumentException
*/
public static function colorFromNormalized(array $normalized): CmykColor
{
if (!in_array(count($normalized), [4, 5])) {
throw new InvalidArgumentException('Number of color channels must be 4 or 5 for ' . static::class);
}
// add alpha value if missing
$normalized = count($normalized) === 4 ? array_pad($normalized, 5, 1) : $normalized;
return new Color(...array_map(
function (string $channel, null|float $normalized) {
try {
return $channel::fromNormalized($normalized);
} catch (TypeError $e) {
throw new InvalidArgumentException(
'Normalized color value must be in range 0 to 1',
previous: $e,
);
}
},
self::$channels,
$normalized,
));
}
/**
* {@inheritdoc}
*
* @see ColorspaceInterface::importColor()
*
* @throws ColorException
*/
public function importColor(ColorInterface $color): CmykColorView on GitHub (pinned to 5598b9e397)
Solutions
- Use 0-based non-negative indexes: ->removeAnimation(0) for the first frame.
- Clamp computed indexes: max(0, $index).
- For 'last frame' semantics, compute the frame count first ($image->count()) and pass count - 1.
Example fix
// before $image->removeAnimation($frame - $offset); // can be -1, throws // after $position = max(0, $frame - $offset); $image->removeAnimation($position);
Defensive patterns
Strategy: validation
Validate before calling
$position = max(0, (int) $position); $image->removeAnimation($position);
Prevention
- Negative indexes are not supported; compute last frame as count() - 1.
- Clamp any index arithmetic result.
- Validate the position parameter as min:0 when it comes from users.
When it happens
Trigger: $image->removeAnimation(-1) expecting Python-style negative indexing; passing a computed index like $frame - $offset that can dip below zero; forwarding a raw query-parameter integer.
Common situations: Assuming negative indexes count from the end (not supported); index arithmetic on user input; off-by-one loops around frame 0.
Related errors
- Failed to apply {class}, unable to re-apply image frame
- Offset is not in the range of frames
- Failed to invert color
- Color channel {class} value must be in range {min} to {max}
- 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/fcc60e18724365d9.
Report an issue: GitHub.