{"record":{"id":"c805a65726bdea38","repo":"Intervention/image","slug":"failed-to-analyze-colorspace","errorCode":null,"errorMessage":"Failed to analyze colorspace","messagePattern":"Failed to analyze colorspace","errorType":"exception","errorClass":"AnalyzerException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Analyzers/ColorspaceAnalyzer.php","lineNumber":47,"sourceCode":"\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":29,"sourceCodeEnd":51,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Analyzers/ColorspaceAnalyzer.php#L29-L51","documentation":"This is the safety net around the whole colorspace analysis: any PHP Error (TypeError, undefined constant access, engine fault surfacing as Error) raised while calling getImageColorspace() or evaluating the match is re-thrown as AnalyzerException with the original chained. Unlike the 'unknown colorspace' variant, the value never reached the match — the Imagick extension itself failed.","triggerScenarios":"Broken ext-imagick builds where the PHP extension was compiled against a different ImageMagick major version than the loaded library; old PECL imagick versions whose methods return unexpected types (e.g. string instead of int) breaking strict comparisons downstream; type errors inside custom colorspace classes pulled in by the match arms.","commonSituations":"System ImageMagick packages upgraded without rebuilding the imagick extension; Docker/Alpine images mixing libmagick versions; minimal images assembled from mismatched -dev packages.","solutions":["Verify the build pair: run php -i | grep -i imagick and confirm the extension's compiled ImageMagick version matches the installed library; rebuild with pecl install imagick after library upgrades.","Smoke-test a freshly read small image — if every image fails, it is the environment, not the file.","If one specific file reproduces it on a healthy build, report upstream with the chained previous Error."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { $colorspace = $image->colorspace(); } catch (AnalyzerException $e) { if ($e->getPrevious() instanceof \\Error) { /* environment failure: alert ops */ } throw $e; }","preventionTips":["Pin matching imagick extension + ImageMagick library versions in Docker images and rebuild both together.","Run a startup smoke test (read a 1x1 PNG) to fail fast on broken builds.","After system package upgrades, reinstall the imagick PECL extension."],"tags":["imagick","colorspace","extension-mismatch","environment"],"backgroundTag":"runtime-extension-mismatch","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}