Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException
Imagick driver can only process colors from instances of
Error message
Imagick driver can only process colors from instances of
What it means
The Imagick driver's colorProcessor()->import() accepts exactly one input type: a native ImagickPixel. Passing anything else — a hex string, an Rgb color object, an array — raises this InvalidArgumentException immediately, before any Imagick work starts. import() is the boundary that converts engine pixels into library color objects, and the engine only speaks ImagickPixel.
Solutions
- Wrap the value in the expected type first: new ImagickPixel('#ff0000') — its constructor accepts the same color strings you tried to pass.
- For user-facing color strings, use the driver's decodeColor() API instead of import().
- Add an instanceof ImagickPixel check before calling import() whenever the value's origin is uncertain.
Example fix
// before
$color = $image->driver()->colorProcessor($image)->import('#ff0000');
// after
$color = $image->driver()->colorProcessor($image)->import(new \ImagickPixel('#ff0000')); Defensive patterns
Strategy: type-guard
Validate before calling
if (!$value instanceof \ImagickPixel) {
$value = new \ImagickPixel((string) $value); // or reject the input
}
$color = $image->driver()->colorProcessor($image)->import($value); Type guard
function isImportableImagickColor(mixed $color): bool
{
return $color instanceof \ImagickPixel;
} Try / catch
try { $color = $processor->import($value); } catch (\Intervention\Image\Exceptions\InvalidArgumentException $e) { /* wrap the value in new ImagickPixel() and retry */ } Prevention
- Remember import() types are driver-specific: ImagickPixel for Imagick, int index for GD.
- Use the driver's decodeColor() for strings and user input.
- Add instanceof checks in driver-agnostic utility code.
When it happens
Trigger: Calling $image->driver()->colorProcessor($image)->import('#ff0000'), ->import(new Rgb(255, 0, 0)), or ->import([255, 0, 0]) in driver-agnostic code — the same call may work under the GD driver, whose import expects a different native type, so the bug only surfaces after switching drivers.
Common situations: Shared utility code originally written and tested against GD, reused with the Imagick driver; integrating pixel values from other Imagick operations or user input.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Failed to import color from
- Argument $native must be of type
- Colorspace
- Failed to apply…
- GD driver can only decode colors in integer or array format
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/2a33f7aef5d93cf3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Drivers/Imagick/ColorProcessor.php:98
$color->channel(Green::class)->value(),
$color->channel(Blue::class)->value(),
$color->channel(Alpha::class)->toString(),
),
);
} catch (ImagickException | ImagickPixelException $e) {
throw new DriverException('Failed to create color', previous: $e);
}
}
/**
* @throws InvalidArgumentException
* @throws DriverException
* @throws NotSupportedException
*/
public function import(mixed $color): ColorInterface
{
if (!$color instanceof ImagickPixel) {
throw new InvalidArgumentException(
'Imagick driver can only process colors from instances of ' . ImagickPixel::class,
);
}
try {
return match ($this->colorspace::class) {
Cmyk::class => $this->colorspace->colorFromNormalized([
$color->getColorValue(Imagick::COLOR_CYAN),
$color->getColorValue(Imagick::COLOR_MAGENTA),
$color->getColorValue(Imagick::COLOR_YELLOW),
$color->getColorValue(Imagick::COLOR_BLACK),
]),
Rgb::class => $this->colorspace->colorFromNormalized([
$color->getColorValue(Imagick::COLOR_RED),
$color->getColorValue(Imagick::COLOR_GREEN),
$color->getColorValue(Imagick::COLOR_BLUE),
$color->getColorValue(Imagick::COLOR_ALPHA),
]),View on GitHub (pinned to 5598b9e397)