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

Failed to read image width

Error message

Failed to read image width

What it means

$image->width() on the Imagick driver is a thin wrapper around Imagick::getImageWidth(); any ImagickException is normalized to this AnalyzerException. On a successfully decoded image the call is essentially infallible, so a failure means the underlying Imagick object is empty or corrupted — the stack was cleared, the object was reused after an earlier error, or its state is broken.

Source

Thrown at src/Drivers/Imagick/Analyzers/WidthAnalyzer.php:23

namespace Intervention\Image\Drivers\Imagick\Analyzers;

use ImagickException;
use Intervention\Image\Analyzers\WidthAnalyzer as GenericWidthAnalyzer;
use Intervention\Image\Exceptions\AnalyzerException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;

class WidthAnalyzer extends GenericWidthAnalyzer implements SpecializedInterface
{
    /**
     * @throws AnalyzerException
     */
    public function analyze(ImageInterface $image): mixed
    {
        try {
            return $image->core()->native()->getImageWidth();
        } catch (ImagickException $e) {
            throw new AnalyzerException('Failed to read image width', previous: $e);
        }
    }
}

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Only query dimensions on images produced by a successful $manager->read() call.
  2. After manual Imagick manipulation, rebuild the library image from the original binary.
  3. If it persists, isolate the file and verify it with the imagick identify CLI.

Example fix

// before
$width = $image->width(); // $image built around an emptied Imagick object

// after: always start from a successfully decoded source
$image = $manager->read($binary);
$width = $image->width();
Defensive patterns

Strategy: try-catch

Validate before calling

// only query dimensions on images from a successful read
if (!$image->core()->native() instanceof \Imagick || $image->core()->count() < 1) {
    throw new RuntimeException('Image resource is not usable');
}

Try / catch

try { $w = $image->width(); } catch (AnalyzerException $e) { /* rebuild from source bytes and retry once */ }

Prevention

When it happens

Trigger: Calling width() on an Image whose Imagick container was emptied via clear()/destroy() by custom code; building an Image around a bare new Imagick(); chained operations after a prior Imagick failure.

Common situations: Custom code holding core()->native() and clearing it; long-running workers with stale handles; partially decoded files from failing delegates.

Related errors


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