{"record":{"id":"f994b63dc4a4b520","repo":"Intervention/image","slug":"first-frame-not-found-in-image","errorCode":null,"errorMessage":"First frame not found in image","messagePattern":"First frame not found in image","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\StateException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Core.php","lineNumber":395,"sourceCode":"        }\n\n        return $this;\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see CollectionInterface::first()\n     *\n     * @throws DriverException\n     * @throws StateException\n     */\n    public function first(): FrameInterface\n    {\n        try {\n            return $this->frame(0);\n        } catch (InvalidArgumentException $e) {\n            throw new StateException('First frame not found in image', previous: $e);\n        }\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see CollectableInterface::last()\n     *\n     * @throws DriverException\n     * @throws StateException\n     */\n    public function last(): FrameInterface\n    {\n        try {\n            return $this->frame($this->count() - 1);\n        } catch (InvalidArgumentException $e) {\n            throw new StateException('Last frame not found in image', previous: $e);\n        }","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Core.php#L377-L413","documentation":"Thrown by Core::first() when frame(0) raises the 'Frame #0 could not be found' InvalidArgumentException, which is then wrapped in this StateException. It means the core holds zero frames, so there is no first frame to return.","triggerScenarios":"Calling $image->core()->first() (or APIs that fetch the base frame) on a core whose frames were all removed — e.g. a slice() that removed everything (offset beyond frame count combined with the rebuild), clear() was called, or the image was constructed around an empty Imagick object.","commonSituations":"Slice logic that computes an offset/length removing the whole animation; reusing an image after $core->clear(); custom code creating Imagick cores manually without adding frames; the decode path producing an empty stack from a zero-byte-ish source.","solutions":["Guard with count($image) > 0 (or $image->core()->count()) before calling first()","Review slice parameters: offset must be < frame count and length >= 1","Do not call clear() on a core you continue to use; re-read the source instead"],"exampleFix":"// before\n$frame = $image->core()->first();\n\n// after\nif ($image->count() === 0) {\n    throw new RuntimeException('empty image');\n}\n$frame = $image->core()->first();","handlingStrategy":"validation","validationCode":"if ($image->count() === 0) {\n    throw new RuntimeException('image has no frames');\n}\n$frame = $image->core()->first();","typeGuard":"function hasFrames(ImageInterface $image): bool\n{\n    return $image->count() > 0;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\StateException;\n\ntry {\n    $frame = $image->core()->first();\n} catch (StateException $e) {\n    $image = $manager->read($source); // empty core: reload\n    $frame = $image->core()->first();\n}","preventionTips":["Check count() > 0 before first()/last()","Never continue using a core after clear() or an all-removing slice","Assert frame count in tests right after decode"],"tags":["imagick","frames","state","empty-collection","animation"],"backgroundTag":"empty-frame-collection","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}