Intervention/image · error · AnalyzerException

Failed to read image height

Error message

Failed to read image height

What it means

$image->height() on the Imagick driver is a thin wrapper around Imagick::getImageHeight(); 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 image stack was cleared, the object was reused after a prior error, or its internal state is bad.

Source

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

namespace Intervention\Image\Drivers\Imagick\Analyzers;

use ImagickException;
use Intervention\Image\Analyzers\HeightAnalyzer as GenericHeightAnalyzer;
use Intervention\Image\Exceptions\AnalyzerException;
use Intervention\Image\Interfaces\ImageInterface;
use Intervention\Image\Interfaces\SpecializedInterface;

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

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Only query dimensions on images produced by a successful $manager->read() call.
  2. After any manual Imagick manipulation, rebuild the library image from the original binary instead of reusing the possibly-broken object.
  3. If it persists, isolate the failing file and inspect it with the imagick identify CLI to confirm corruption.

Example fix

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

// after: always start from a successfully decoded source
$image = $manager->read($binary);
$height = $image->height();
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 { $h = $image->height(); } catch (AnalyzerException $e) { /* rebuild from source bytes and retry once */ }

Prevention

When it happens

Trigger: Calling height() 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 an earlier Imagick failure left the object in a broken state.

Common situations: Custom code that holds core()->native() and clears or mutates 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/3f91406227166a34. Report an issue: GitHub.