{"record":{"id":"2259531fd3b889e1","repo":"Intervention/image","slug":"failed-to-read-image-size","errorCode":null,"errorMessage":"Failed to read image size","messagePattern":"Failed to read image size","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\AnalyzerException","httpStatus":null,"severity":"error","filePath":"src/Image.php","lineNumber":367,"sourceCode":"     */\n    public function height(): int\n    {\n        return $this->analyze(new HeightAnalyzer());\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ImageInterface::size()\n     *\n     * @throws AnalyzerException\n     */\n    public function size(): SizeInterface\n    {\n        try {\n            return new Size($this->width(), $this->height());\n        } catch (InvalidArgumentException $e) {\n            throw new AnalyzerException('Failed to read image size', previous: $e);\n        }\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ImageInterface::colorspace()\n     *\n     * @throws AnalyzerException\n     */\n    public function colorspace(): ColorspaceInterface\n    {\n        return $this->analyze(new ColorspaceAnalyzer());\n    }\n\n    /**\n     * {@inheritdoc}\n     *","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Image.php#L349-L385","documentation":"Image::size() builds a Size object from width() and height() analyzer results; if the Size constructor rejects those values (a dimension < 0, see Size.php:36-46), the InvalidArgumentException is wrapped as AnalyzerException('Failed to read image size'). Note this specific message only appears for the Size-construction failure — a failing width()/height() analyzer itself propagates a different AnalyzerException from the driver.","triggerScenarios":"An image whose driver core reports a negative width or height — e.g. corrupted image data, a malformed/crafted file that passed decoding, or a driver core left in an inconsistent state. Normal decoded or created images return dimensions >= 0 and never hit this.","commonSituations":"Processing untrusted uploads with hand-crafted headers, a partially-failed prior modification leaving a broken core, or driver edge cases with exotic formats. Rare in practice; when it appears the image object itself is not trustworthy.","solutions":["Inspect getPrevious() — it carries the original InvalidArgumentException naming the negative dimension","Discard and re-read the source from its original bytes; if it reproduces, the file itself is malformed","Validate uploads (dimension sanity check right after read()) before feeding them into a processing pipeline","If reproducible with a valid file, report a driver bug with the sample image"],"exampleFix":"// before\n$size = $image->size(); // AnalyzerException on corrupted core\n\n// after\ntry {\n    $size = $image->size();\n} catch (AnalyzerException $e) {\n    $image = $manager->read($originalBytes); // re-read from source\n    $size = $image->size();\n}","handlingStrategy":"try-catch","validationCode":"try {\n    $size = $image->size(); // cheap pre-flight on untrusted images\n} catch (AnalyzerException $e) {\n    // reject/quarantine the source file here\n}","typeGuard":"function hasReadableSize(ImageInterface $image): bool\n{\n    try { $image->size(); return true; }\n    catch (\\Intervention\\Image\\Exceptions\\AnalyzerException) { return false; }\n}","tryCatchPattern":"try {\n    $size = $image->size();\n} catch (AnalyzerException $e) {\n    $root = $e->getPrevious(); // original Size InvalidArgumentException\n    // discard image object; re-read from original bytes once\n}","preventionTips":["Run size() once right after read() as an integrity gate on untrusted uploads","Do not reuse image objects after a caught modifier/analyzer failure","Keep original bytes/path around so a re-read is possible"],"tags":["analyzer","size","dimensions","corruption"],"backgroundTag":"image-analysis-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}