{"record":{"id":"6787211840037731","repo":"Intervention/image","slug":"colorspace-colorspace-class-is-not-supported-by","errorCode":null,"errorMessage":"Colorspace {colorspace::class} is not supported by driver","messagePattern":"Colorspace (.+?) is not supported by driver","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/ColorspaceModifier.php","lineNumber":91,"sourceCode":"            return Imagick::COLORSPACE_HSB;\n        }\n\n        try {\n            if ($colorspace instanceof Oklab && defined(Imagick::class . '::COLORSPACE_OKLAB')) {\n                return constant(Imagick::class . '::COLORSPACE_OKLAB');\n            }\n\n            if ($colorspace instanceof Oklch && defined(Imagick::class . '::COLORSPACE_OKLCH')) {\n                return constant(Imagick::class . '::COLORSPACE_OKLCH');\n            }\n        } catch (Error $e) {\n            throw new ModifierException(\n                'Failed to convert colorspace to Imagick constant',\n                previous: $e,\n            );\n        }\n\n        throw new NotSupportedException('Colorspace ' . $colorspace::class . ' is not supported by driver');\n    }\n}\n","sourceCodeStart":73,"sourceCodeEnd":94,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/ColorspaceModifier.php#L73-L94","documentation":"Thrown by ColorspaceModifier::imagickColorspaceOrFail() when the target colorspace class has no Imagick mapping. Supported: Rgb, Cmyk, Hsl, Hsv, and Oklab/Oklch only when the corresponding Imagick constants exist. Any other ColorspaceInterface implementation — including Oklab/Oklch on old builds lacking COLORSPACE_OKLAB/COLORSPACE_OKLCH — gets this NotSupportedException.","triggerScenarios":"Passing a custom colorspace class implementing ColorspaceInterface to $image->colorspace(); targeting Oklab or Oklch on ImageMagick/ext-imagick builds older than the constants' introduction; passing an enum/string value that resolves to an unmapped class.","commonSituations":"Using newer library features (Oklab/Oklch) on a server pinned to older ImageMagick; custom colorspaces written for the GD driver reused with Imagick; CI passing (new ImageMagick) while production fails (old one).","solutions":["Target one of the always-supported colorspaces: Rgb, Cmyk, Hsl or Hsv.","For Oklab/Oklch, upgrade ImageMagick (>= 7.1-ish) and the pecl/imagick extension so the constants exist: php -r 'var_dump(defined(\"\\\\Imagick::COLORSPACE_OKLAB\"));'.","If you authored a custom colorspace, add a driver-supported path or map it to the nearest supported one (e.g. sRGB) instead of passing it to the Imagick driver.","Feature-detect before calling (see validation guard) so deployments degrade gracefully across environments."],"exampleFix":"// before\n$image->colorspace(\\Intervention\\Image\\Colors\\Oklch\\Colorspace::class); // old imagick -> NotSupportedException\n\n// after\n$target = defined(\\Imagick::class . '::COLORSPACE_OKLCH')\n    ? \\Intervention\\Image\\Colors\\Oklch\\Colorspace::class\n    : \\Intervention\\Image\\Colors\\Rgb\\Colorspace::class;\n$image->colorspace($target);","handlingStrategy":"validation","validationCode":"use Intervention\\Image\\Colors\\{Rgb\\Colorspace as Rgb, Cmyk\\Colorspace as Cmyk, Hsl\\Colorspace as Hsl, Hsv\\Colorspace as Hsv, Oklab\\Colorspace as Oklab, Oklch\\Colorspace as Oklch};\n\nfunction isSupportedByImagickDriver(string $colorspace): bool\n{\n    return match ($colorspace) {\n        Rgb::class, Cmyk::class, Hsl::class, Hsv::class => true,\n        Oklab::class => defined(\\Imagick::class . '::COLORSPACE_OKLAB'),\n        Oklch::class => defined(\\Imagick::class . '::COLORSPACE_OKLCH'),\n        default => false,\n    };\n}","typeGuard":"function supportedColorspaceOrDefault(string $colorspace, string $default = \\Intervention\\Image\\Colors\\Rgb\\Colorspace::class): string\n{\n    $map = [\n        \\Intervention\\Image\\Colors\\Rgb\\Colorspace::class => true,\n        \\Intervention\\Image\\Colors\\Cmyk\\Colorspace::class => true,\n        \\Intervention\\Image\\Colors\\Hsl\\Colorspace::class => true,\n        \\Intervention\\Image\\Colors\\Hsv\\Colorspace::class => true,\n        \\Intervention\\Image\\Colors\\Oklab\\Colorspace::class => defined(\\Imagick::class . '::COLORSPACE_OKLAB'),\n        \\Intervention\\Image\\Colors\\Oklch\\Colorspace::class => defined(\\Imagick::class . '::COLORSPACE_OKLCH'),\n    ];\n    return ($map[$colorspace] ?? false) ? $colorspace : $default;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\NotSupportedException;\ntry {\n    $image->colorspace($target);\n} catch (NotSupportedException $e) {\n    // degrade to sRGB rather than failing the request\n    $image->colorspace(\\Intervention\\Image\\Colors\\Rgb\\Colorspace::class);\n}","preventionTips":["Restrict colorspace choices in config/UI to the driver-supported set: Rgb, Cmyk, Hsl, Hsv, plus Oklab/Oklch behind a feature check.","Keep CI and production ImageMagick versions aligned so constant availability matches.","Do not pass custom ColorspaceInterface implementations to the Imagick driver without adding a native mapping."],"tags":["imagick","colourspace","oklab","oklch","not-supported","feature-detection"],"backgroundTag":"colorspace-not-supported","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}