Intervention/image · error · Intervention\Image\Exceptions\DriverException

Failed to convert image to sRGB

Error message

Failed to convert image to sRGB

What it means

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.

Source

Thrown at src/Drivers/Imagick/Decoders/NativeObjectDecoder.php:83

        // turn images with colorspace 'GRAY' into 'SRGB' to avoid working on
        // grayscale colorspace images as this results images loosing color
        // information when placed into this image.
        try {
            if ($input->getImageColorspace() === Imagick::COLORSPACE_GRAY) {
                $input->setImageColorspace(Imagick::COLORSPACE_SRGB);
            }

            // AVIF/HEIF store their pixels in a luma/chroma (YCbCr) colorspace.
            // Recent ImageMagick normalizes this to sRGB on decode, but older
            // releases report the image as YCbCr, which leaves every later color
            // operation (colorspace analysis, pixel reads) working on raw
            // luma/chroma values. Convert it to sRGB so colors are correct.
            if ($input->getImageColorspace() === Imagick::COLORSPACE_YCBCR) {
                $input->transformImageColorspace(Imagick::COLORSPACE_SRGB);
            }
        } catch (ImagickException $e) {
            throw new DriverException('Failed to convert image to sRGB', previous: $e);
        }

        // create image object
        $image = new Image($this->driver(), new Core($input));

        // If autoOrientation is disabled, automatic image alignment should be prevented.
        // Therefore, it is set to "undefined" here. To still be able to correct the
        // orientation manually later, we save the original value.
        if ($this->driver()->config()->autoOrientation === false) {
            try {
                $image->core()->meta()->set('originalImageOrientation', $input->getImageOrientation());
                $input->setImageOrientation(Imagick::ORIENTATION_UNDEFINED);
            } catch (ImagickException $e) {
                throw new ImageDecoderException(
                    'Failed to set adjust image orientation',
                    previous: $e,
                );
            }

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Read $e->getPrevious()->getMessage() for the native ImageMagick reason
  2. Install/enable LittleCMS (apt install liblcms2-2, or rebuild ImageMagick --with-lcms) or use a Docker image that includes it
  3. Loosen ImageMagick resource limits in policy.xml (memory, area) for large files
  4. Convert externally (convert in.tif -colorspace sRGB out.png) and read the result
  5. Upgrade ImageMagick/imagick if the native error indicates a known transformImageColorspace bug
Defensive patterns

Strategy: try-catch

Try / catch

try {
    $image = $manager->read($path);
} catch (\Intervention\Image\Exceptions\DriverException $e) {
    $native = $e->getPrevious()?->getMessage() ?? 'unknown';
    throw new RuntimeException('Colorspace normalization failed: ' . $native, 0, $e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/4f9f5d091638b404. Report an issue: GitHub.