Intervention/image · error · Intervention\Image\Exceptions\DriverException
Failed to count image frames
Error message
Failed to count image frames
What it means
Thrown by Core::count() when Imagick::getNumberImages() raises an ImagickException. The core should always be able to report its frame count, so this error signals that the underlying Imagick object is destroyed, cleared, or in a corrupted internal state.
Source
Thrown at src/Drivers/Imagick/Core.php:227
throw new DriverException('Failed to add image frame', previous: $e);
}
return $this;
}
/**
* {@inheritdoc}
*
* @see CoreInterface::count()
*
* @throws DriverException
*/
public function count(): int
{
try {
return $this->imagick->getNumberImages();
} catch (ImagickException $e) {
throw new DriverException('Failed to count image frames', previous: $e);
}
}
/**
* {@inheritdoc}
*
* @see Iterator::rewind()
*
* @throws DriverException
*/
public function current(): mixed
{
try {
$this->imagick->setIteratorIndex($this->iteratorIndex);
return new Frame($this->imagick->current());
} catch (ImagickException | RuntimeException $e) {
throw new DriverException('Failed to iterate image frames', previous: $e);View on GitHub (pinned to 5598b9e397)
Solutions
- Read the previous ImagickException to confirm resource-destruction vs. corruption
- Do not reuse an Image whose core was mutated when an earlier operation threw; re-read the source
- Avoid calling $image->core()->clear() manually unless you discard the image afterwards
- Keep the ImageManager->read() and the operations in the same scope so PHP does not garbage-collect the native object early
Defensive patterns
Strategy: try-catch
Try / catch
use Intervention\Image\Exceptions\DriverException;
try {
$frames = $image->count();
} catch (DriverException $e) {
// core is unusable (destroyed/cleared native object)
$image = $manager->read($sourcePath);
$frames = $image->count();
} Prevention
- Do not call $image->core()->clear() on images you keep using
- After any exception from core mutations, re-read the source instead of continuing
- Perform read + operate + encode within one scope so the native object outlives its usage
When it happens
Trigger: Calling $image->count(), or any API that internally counts frames (Core::last(), RemoveAnimationModifier::normalizePosition() with a '50%' string position), after the native Imagick object was destructed, cleared via clear(), or invalidated by a failed operation that left the core half-modified.
Common situations: Holding an Image across long-running jobs while its Imagick resource was freed; reusing a core after an exception in slice()/add(); reference bugs where the Imagick object was replaced by a destroyed handle; imagick extension crashes mid-operation.
Related errors
- First frame not found in image
- Last frame not found in image
- Given color space must implement Intervention\Image\Interfac
- Failed to get current frame data
- Failed to slice image
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/1f7345c5de048cb4.
Report an issue: GitHub.