{"record":{"id":"4f9f5d091638b404","repo":"Intervention/image","slug":"failed-to-convert-image-to-srgb","errorCode":null,"errorMessage":"Failed to convert image to sRGB","messagePattern":"Failed to convert image to sRGB","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\DriverException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Decoders/NativeObjectDecoder.php","lineNumber":83,"sourceCode":"\n        // turn images with colorspace 'GRAY' into 'SRGB' to avoid working on\n        // grayscale colorspace images as this results images loosing color\n        // information when placed into this image.\n        try {\n            if ($input->getImageColorspace() === Imagick::COLORSPACE_GRAY) {\n                $input->setImageColorspace(Imagick::COLORSPACE_SRGB);\n            }\n\n            // AVIF/HEIF store their pixels in a luma/chroma (YCbCr) colorspace.\n            // Recent ImageMagick normalizes this to sRGB on decode, but older\n            // releases report the image as YCbCr, which leaves every later color\n            // operation (colorspace analysis, pixel reads) working on raw\n            // luma/chroma values. Convert it to sRGB so colors are correct.\n            if ($input->getImageColorspace() === Imagick::COLORSPACE_YCBCR) {\n                $input->transformImageColorspace(Imagick::COLORSPACE_SRGB);\n            }\n        } catch (ImagickException $e) {\n            throw new DriverException('Failed to convert image to sRGB', previous: $e);\n        }\n\n        // create image object\n        $image = new Image($this->driver(), new Core($input));\n\n        // If autoOrientation is disabled, automatic image alignment should be prevented.\n        // Therefore, it is set to \"undefined\" here. To still be able to correct the\n        // orientation manually later, we save the original value.\n        if ($this->driver()->config()->autoOrientation === false) {\n            try {\n                $image->core()->meta()->set('originalImageOrientation', $input->getImageOrientation());\n                $input->setImageOrientation(Imagick::ORIENTATION_UNDEFINED);\n            } catch (ImagickException $e) {\n                throw new ImageDecoderException(\n                    'Failed to set adjust image orientation',\n                    previous: $e,\n                );\n            }","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Decoders/NativeObjectDecoder.php#L65-L101","documentation":"The decoder normalizes GRAY and YCbCr (AVIF/HEIF store luma/chroma) colorspaces to sRGB via setImageColorspace()/transformImageColorspace(), and the conversion threw. This is usually an ImageMagick build/configuration problem (missing LittleCMS color management) or resource exhaustion on large images. Thrown as DriverException with the native error chained as previous.","triggerScenarios":"Reading a grayscale TIFF/PNG (COLORSPACE_GRAY) or an AVIF/HEIC file (COLORSPACE_YCBCR) on an ImageMagick built without lcms2; converting a very large image under tight policy.xml memory/area limits.","commonSituations":"Alpine/minimal containers where the imagemagick package lacks lcms2; scanned grayscale TIFFs in document pipelines; iPhone HEIC photos hitting the YCbCr path on older ImageMagick releases.","solutions":["Read $e->getPrevious()->getMessage() for the native ImageMagick reason","Install/enable LittleCMS (apt install liblcms2-2, or rebuild ImageMagick --with-lcms) or use a Docker image that includes it","Loosen ImageMagick resource limits in policy.xml (memory, area) for large files","Convert externally (convert in.tif -colorspace sRGB out.png) and read the result","Upgrade ImageMagick/imagick if the native error indicates a known transformImageColorspace bug"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    $image = $manager->read($path);\n} catch (\\Intervention\\Image\\Exceptions\\DriverException $e) {\n    $native = $e->getPrevious()?->getMessage() ?? 'unknown';\n    throw new RuntimeException('Colorspace normalization failed: ' . $native, 0, $e);\n}","preventionTips":["Bake lcms2 into every image variant of your containers","Smoke-test grayscale TIFF and HEIC/AVIF files in CI for each environment","Check `convert -list configure | grep -i lcms` when provisioning new hosts"],"tags":["imagick","colorspace","srgb","lcms","grayscale","avif"],"backgroundTag":"colorspace-conversion-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}