{"record":{"id":"eee69bdbab1753b8","repo":"Intervention/image","slug":"failed-to-read-image-width","errorCode":null,"errorMessage":"Failed to read image width","messagePattern":"Failed to read image width","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\AnalyzerException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Analyzers/WidthAnalyzer.php","lineNumber":23,"sourceCode":"namespace Intervention\\Image\\Drivers\\Imagick\\Analyzers;\n\nuse ImagickException;\nuse Intervention\\Image\\Analyzers\\WidthAnalyzer as GenericWidthAnalyzer;\nuse Intervention\\Image\\Exceptions\\AnalyzerException;\nuse Intervention\\Image\\Interfaces\\ImageInterface;\nuse Intervention\\Image\\Interfaces\\SpecializedInterface;\n\nclass WidthAnalyzer extends GenericWidthAnalyzer implements SpecializedInterface\n{\n    /**\n     * @throws AnalyzerException\n     */\n    public function analyze(ImageInterface $image): mixed\n    {\n        try {\n            return $image->core()->native()->getImageWidth();\n        } catch (ImagickException $e) {\n            throw new AnalyzerException('Failed to read image width', previous: $e);\n        }\n    }\n}\n","sourceCodeStart":5,"sourceCodeEnd":27,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Analyzers/WidthAnalyzer.php#L5-L27","documentation":"$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.","triggerScenarios":"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.","commonSituations":"Custom code holding core()->native() and clearing it; long-running workers with stale handles; partially decoded files from failing delegates.","solutions":["Only query dimensions on images produced by a successful $manager->read() call.","After manual Imagick manipulation, rebuild the library image from the original binary.","If it persists, isolate the file and verify it with the imagick identify CLI."],"exampleFix":"// before\n$width = $image->width(); // $image built around an emptied Imagick object\n\n// after: always start from a successfully decoded source\n$image = $manager->read($binary);\n$width = $image->width();","handlingStrategy":"try-catch","validationCode":"// only query dimensions on images from a successful read\nif (!$image->core()->native() instanceof \\Imagick || $image->core()->count() < 1) {\n    throw new RuntimeException('Image resource is not usable');\n}","typeGuard":null,"tryCatchPattern":"try { $w = $image->width(); } catch (AnalyzerException $e) { /* rebuild from source bytes and retry once */ }","preventionTips":["Never clear()/destroy() the native Imagick of a live library image.","Rebuild images from binary after any manual Imagick surgery.","Treat width()/height() failures as a signal the whole object is suspect."],"tags":["imagick","width","analyzer","imagickexception","invalid-resource"],"backgroundTag":"invalid-image-resource","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}