{"record":{"id":"4bcc015014de3702","repo":"Intervention/image","slug":"only-rgb-colorspace-is-supported-by-gd-driver","errorCode":null,"errorMessage":"Only RGB colorspace is supported by GD driver","messagePattern":"Only RGB colorspace is supported by GD driver","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Modifiers/ColorspaceModifier.php","lineNumber":25,"sourceCode":"use Intervention\\Image\\Colors\\Rgb\\Colorspace as RgbColorspace;\nuse Intervention\\Image\\Exceptions\\NotSupportedException;\nuse Intervention\\Image\\Interfaces\\ImageInterface;\nuse Intervention\\Image\\Interfaces\\SpecializedInterface;\nuse Intervention\\Image\\Modifiers\\ColorspaceModifier as GenericColorspaceModifier;\n\nclass ColorspaceModifier extends GenericColorspaceModifier implements SpecializedInterface\n{\n    /**\n     * {@inheritdoc}\n     *\n     * @see ModifierInterface::apply()\n     *\n     * @throws NotSupportedException\n     */\n    public function apply(ImageInterface $image): ImageInterface\n    {\n        if (!$this->targetColorspace() instanceof RgbColorspace) {\n            throw new NotSupportedException(\n                'Only RGB colorspace is supported by GD driver',\n            );\n        }\n\n        return $image;\n    }\n}\n","sourceCodeStart":7,"sourceCodeEnd":33,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Modifiers/ColorspaceModifier.php#L7-L33","documentation":"GD has no colorspace conversion capability and only operates in RGB. The ColorspaceModifier therefore rejects any target colorspace that is not an RgbColorspace — for example converting to cmyk or gray — with NotSupportedException, while leaving RGB targets as a no-op.","triggerScenarios":"$image->colorspace('cmyk') or ->colorspace('gray') while the manager runs on the GD driver.","commonSituations":"Print workflows assuming CMYK output, code shared between drivers that works under Imagick but is deployed with GD, attempts to get grayscale via colorspace() instead of ->greyscale().","solutions":["Use ->greyscale() for grayscale output on the GD driver","Switch the manager to the Imagick driver when CMYK conversion is actually required","Gate colorspace calls by driver capability before invoking them","Convert colorspace in an external tool (ImageMagick CLI) if GD must stay"],"exampleFix":"// before\n$image = $manager->read('print.tif');\n$image->colorspace('cmyk'); // NotSupportedException on GD\n\n// after\n$imagickManager = ImageManager::usingDriver(ImagickDriver::class);\n$image = $imagickManager->read('print.tif');\n$image->colorspace('cmyk');","handlingStrategy":"fallback","validationCode":"$allowed = ['rgb', 'srgb'];\nif (!in_array(strtolower($target), $allowed, true) && usingGdDriver($manager)) {\n    throw new RuntimeException('GD supports only RGB; use Imagick for ' . $target);\n}\n$image->colorspace($target);","typeGuard":null,"tryCatchPattern":"try {\n    $image->colorspace($target);\n} catch (NotSupportedException $e) {\n    $image = ImageManager::usingDriver(ImagickDriver::class)->read($source);\n    $image->colorspace($target);\n}","preventionTips":["Use ->greyscale() for grayscale on GD","Decide the driver by required features (CMYK implies Imagick)","Centralize colorspace logic so driver mismatches surface early"],"tags":["colorspace","cmyk","rgb","unsupported-feature","gd"],"backgroundTag":"unsupported-colorspace","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}