Intervention/image · warning · DriverException

Unable to read ImageMagick version number

Error message

Unable to read ImageMagick version number

What it means

Driver::version() parses Imagick::getVersion()['versionString'] with a semver-shaped regex anchored to 'ImageMagick X.Y.Z'; the string did not match. Happens on non-standard builds that report customized version strings (distro patches, --with-package-name renames, forks) or when a future release changes the format. Purely informational API failure.

Source

Thrown at src/Drivers/Imagick/Driver.php:151

            return false;
        }

        return count(Imagick::queryFormats($format->name)) >= 1;
    }

    /**
     * Return version of ImageMagick library
     *
     * @throws DriverException
     */
    public function version(): string
    {
        $pattern = '/^ImageMagick (?P<version>(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)' .
            '(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?' .
            '(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)/';

        if (preg_match($pattern, Imagick::getVersion()['versionString'], $matches) !== 1) {
            throw new DriverException('Unable to read ImageMagick version number');
        }

        return $matches['version'];
    }

    /**
     * Apply default settings for native image object.
     *
     * @throws DriverException
     */
    private function applyDefaultSettings(Imagick $imagick): Imagick
    {
        try {
            $background = new ImagickPixel('rgba(255, 255, 255, 0)');

            $imagick->setType(Imagick::IMGTYPE_UNDEFINED);
            $imagick->setImageType(Imagick::IMGTYPE_UNDEFINED);
            $imagick->setColorspace(Imagick::COLORSPACE_SRGB);

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Print Imagick::getVersion() to see the actual versionString and confirm it is non-standard
  2. Use the numeric form instead: Imagick::getVersion()['versionNumber'] (hex), or pin a standard distro ImageMagick package
  3. Check for a newer release of intervention/image that extends the regex for new build strings

Example fix

// before
$version = $driver->version(); // throws on custom build strings

// after
$info = Imagick::getVersion();
$version = sprintf('0x%x', $info['versionNumber']); // numeric fallback, always present
Defensive patterns

Strategy: try-catch

Try / catch

try {
    $version = $driver->version();
} catch (\Intervention\Image\Exceptions\DriverException $e) {
    $info = \Imagick::getVersion();
    $version = sprintf('0x%x', $info['versionNumber']); // numeric fallback
}

Prevention

When it happens

Trigger: Calling $driver->version() (or a feature surfacing it) on self-compiled/customized ImageMagick builds, some Homebrew/macports variants, or rebranded forks; a brand-new ImageMagick release with an unanticipated string shape.

Common situations: Version-gating code that checks driver capabilities; unusual container base images with patched ImageMagick packages.

Related errors


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