{"record":{"id":"207214922f42d9b0","repo":"Intervention/image","slug":"failed-to-analyze-unknown-colorspace","errorCode":null,"errorMessage":"Failed to analyze unknown colorspace","messagePattern":"Failed to analyze unknown colorspace","errorType":"exception","errorClass":"AnalyzerException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Analyzers/ColorspaceAnalyzer.php","lineNumber":44,"sourceCode":"    {\n        try {\n            $colorspace = $image->core()->native()->getImageColorspace();\n\n            // OKLAB/OKLCH only exist on recent ImageMagick builds, so the\n            // constants are resolved through defined()/constant() (mirroring the\n            // ColorspaceModifier) to avoid referencing them where they are\n            // undefined. Any unexpected resolution error is normalized below.\n            return match (true) {\n                $colorspace === Imagick::COLORSPACE_CMYK => new Cmyk(),\n                $colorspace === Imagick::COLORSPACE_SRGB,\n                $colorspace === Imagick::COLORSPACE_RGB => new Rgb(),\n                $colorspace === Imagick::COLORSPACE_HSL => new Hsl(),\n                $colorspace === Imagick::COLORSPACE_HSB => new Hsv(),\n                defined(Imagick::class . '::COLORSPACE_OKLAB')\n                    && $colorspace === constant(Imagick::class . '::COLORSPACE_OKLAB') => new Oklab(),\n                defined(Imagick::class . '::COLORSPACE_OKLCH')\n                    && $colorspace === constant(Imagick::class . '::COLORSPACE_OKLCH') => new Oklch(),\n                default => throw new AnalyzerException('Failed to analyze unknown colorspace'),\n            };\n        } catch (Error $e) {\n            throw new AnalyzerException('Failed to analyze colorspace', previous: $e);\n        }\n    }\n}\n","sourceCodeStart":26,"sourceCodeEnd":51,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Analyzers/ColorspaceAnalyzer.php#L26-L51","documentation":"$image->colorspace() on the Imagick driver maps the native Imagick colorspace constant onto one of the library's colorspace classes. The match covers CMYK, sRGB/RGB, HSL, HSB and (on recent builds) OKLAB/OKLCH; every other colorspace — most commonly COLORSPACE_GRAY from grayscale JPEGs/PNGs, or LAB/XYZ/REC709 variants from TIFFs — falls into the default arm and throws AnalyzerException.","triggerScenarios":"Calling $image->colorspace() on a grayscale PNG/JPEG; LAB or exotic TIFFs from scanners and Adobe exports; images pre-processed by other ImageMagick commands so they report HSL/HSB; any analyzer that indirectly resolves the colorspace.","commonSituations":"Batch pipelines mixing camera JPEGs with scanned grayscale TIFFs; assets pushed through external ImageMagick steps before reaching the library.","solutions":["Normalize the colorspace before analysis: $image->setColorspace(\\Intervention\\Image\\Colors\\Rgb\\Colorspace::class) so the analyzer always sees a supported value.","Wrap colorspace() in try/catch AnalyzerException and default to an sRGB assumption in your logic.","Convert grayscale/LAB sources to sRGB once at ingest if you control storage."],"exampleFix":"// before\n$colorspace = $image->colorspace(); // throws on grayscale images\n\n// after: treat unreportable colorspaces as sRGB\ntry {\n    $colorspace = $image->colorspace();\n} catch (\\Intervention\\Image\\Exceptions\\AnalyzerException) {\n    $colorspace = new \\Intervention\\Image\\Colors\\Rgb\\Colorspace();\n}","handlingStrategy":"try-catch","validationCode":"// peek at the native colorspace before calling colorspace()\n$cs = $image->core()->native()->getImageColorspace();\n$known = [Imagick::COLORSPACE_CMYK, Imagick::COLORSPACE_SRGB, Imagick::COLORSPACE_RGB, Imagick::COLORSPACE_HSL, Imagick::COLORSPACE_HSB];\nif (!in_array($cs, $known, true)) {\n    $image = $image->setColorspace(\\Intervention\\Image\\Colors\\Rgb\\Colorspace::class);\n}","typeGuard":null,"tryCatchPattern":"try { $colorspace = $image->colorspace(); } catch (AnalyzerException) { $colorspace = new \\Intervention\\Image\\Colors\\Rgb\\Colorspace(); }","preventionTips":["Normalize all inputs to sRGB at ingest.","Expect grayscale scans/TIFFs in mixed batches and branch before analysis.","Log unknown colorspaces with the native constant value for triage."],"tags":["imagick","colorspace","analyzer","grayscale"],"backgroundTag":"unsupported-colorspace","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}