Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException
Unable to parse HSV color from input "{input}"
Error message
Unable to parse HSV color from input "{input}" What it means
Hsv\Color::parse() accepts only strings decodable by the HSV string color decoder, i.e. input beginning with 'hsv' such as 'hsv(120, 100%, 50%)'. If no decoder supports the input, the NotSupportedException/DriverException from the input handler is wrapped in this InvalidArgumentException repeating the input. A string that starts with 'hsv' but is malformed produces the separate 'Invalid hsv() color syntax' error instead.
Source
Thrown at src/Colors/Hsv/Color.php:64
public static function create(int|Hue $h, int|Saturation $s, int|Value $v, float|Alpha $a = 1): self
{
return new self($h, $s, $v, $a);
}
/**
* Parse HSV 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 HSV 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
- Use HSV syntax: Hsv\Color::parse('hsv(120, 100%, 50%)')
- Parse hex/rgb with Rgb\Color::parse() and convert: ->toColorspace(Hsv\Colorspace::class)
- Trim input before parsing
- Route arbitrary formats through a generic parser and convert afterwards, instead of the HSV-specific one
Example fix
// before
$hsv = Hsv\Color::parse('#00ff00');
// after
$hsv = Rgb\Color::parse('#00ff00')->toColorspace(Hsv\Colorspace::class); Defensive patterns
Strategy: validation
Validate before calling
$trimmed = trim((string) $input);
if (!str_starts_with(strtolower($trimmed), 'hsv')) {
// not parseable by Hsv\Color::parse(); use Rgb\Color::parse() + conversion
} Type guard
function isHsvParseable(mixed $input): bool
{
return is_string($input) && str_starts_with(strtolower(trim($input)), 'hsv');
} Try / catch
use Intervention\Image\Exceptions\InvalidArgumentException as ImageArg;
try {
$hsv = Hsv\Color::parse($input);
} catch (ImageArg $e) {
$hsv = Rgb\Color::parse($input)->toColorspace(Hsv\Colorspace::class);
} Prevention
- Route hex/rgb/named formats through Rgb\Color::parse() and convert
- Trim input before parsing
- Centralize color-string parsing in one helper so formats cannot be mismatched
When it happens
Trigger: Hsv\Color::parse('#00ff00'), Hsv\Color::parse('rgb(0, 255, 0)'), Hsv\Color::parse('green'), Hsv\Color::parse('') - none start with 'hsv'; also leading whitespace or a BOM in front of an otherwise valid string.
Common situations: Passing hex/RGB values from databases or config into the HSV-specific parser; generic user input routed to the wrong colorspace-specific parse method; template/CSV sources adding invisible leading characters.
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
- Invalid cmyk() color syntax "{input}"
- Unable to parse HSL color from input "{input}"
- Invalid hsl() color syntax "{input}"
- Number of color channels must be 3 or 4 for {class}
- Normalized color value must be in range 0 to 1
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/25e3fffcd2be9d17.
Report an issue: GitHub.