{"record":{"id":"2a33f7aef5d93cf3","repo":"Intervention/image","slug":"imagick-driver-can-only-process-colors-from-instan","errorCode":null,"errorMessage":"Imagick driver can only process colors from instances of ","messagePattern":"Imagick driver can only process colors from instances of ","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/ColorProcessor.php","lineNumber":98,"sourceCode":"                    $color->channel(Green::class)->value(),\n                    $color->channel(Blue::class)->value(),\n                    $color->channel(Alpha::class)->toString(),\n                ),\n            );\n        } catch (ImagickException | ImagickPixelException $e) {\n            throw new DriverException('Failed to create color', previous: $e);\n        }\n    }\n\n    /**\n     * @throws InvalidArgumentException\n     * @throws DriverException\n     * @throws NotSupportedException\n     */\n    public function import(mixed $color): ColorInterface\n    {\n        if (!$color instanceof ImagickPixel) {\n            throw new InvalidArgumentException(\n                'Imagick driver can only process colors from instances of ' . ImagickPixel::class,\n            );\n        }\n\n        try {\n            return match ($this->colorspace::class) {\n                Cmyk::class => $this->colorspace->colorFromNormalized([\n                    $color->getColorValue(Imagick::COLOR_CYAN),\n                    $color->getColorValue(Imagick::COLOR_MAGENTA),\n                    $color->getColorValue(Imagick::COLOR_YELLOW),\n                    $color->getColorValue(Imagick::COLOR_BLACK),\n                ]),\n                Rgb::class => $this->colorspace->colorFromNormalized([\n                    $color->getColorValue(Imagick::COLOR_RED),\n                    $color->getColorValue(Imagick::COLOR_GREEN),\n                    $color->getColorValue(Imagick::COLOR_BLUE),\n                    $color->getColorValue(Imagick::COLOR_ALPHA),\n                ]),","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/ColorProcessor.php#L80-L116","documentation":"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.","triggerScenarios":"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.","commonSituations":"Shared utility code originally written and tested against GD, reused with the Imagick driver; integrating pixel values from other Imagick operations or user input.","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."],"exampleFix":"// before\n$color = $image->driver()->colorProcessor($image)->import('#ff0000');\n\n// after\n$color = $image->driver()->colorProcessor($image)->import(new \\ImagickPixel('#ff0000'));","handlingStrategy":"type-guard","validationCode":"if (!$value instanceof \\ImagickPixel) {\n    $value = new \\ImagickPixel((string) $value); // or reject the input\n}\n$color = $image->driver()->colorProcessor($image)->import($value);","typeGuard":"function isImportableImagickColor(mixed $color): bool\n{\n    return $color instanceof \\ImagickPixel;\n}","tryCatchPattern":"try { $color = $processor->import($value); } catch (\\Intervention\\Image\\Exceptions\\InvalidArgumentException $e) { /* wrap the value in new ImagickPixel() and retry */ }","preventionTips":["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."],"tags":["imagick","colorprocessor","import","type-error","imagickpixel"],"backgroundTag":"invalid-argument-type","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}