{"record":{"id":"980092adc15f9987","repo":"Intervention/image","slug":"failed-to-read-image-resolution-980092","errorCode":null,"errorMessage":"Failed to read image resolution","messagePattern":"Failed to read image resolution","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\AnalyzerException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Analyzers/ResolutionAnalyzer.php","lineNumber":29,"sourceCode":"use Intervention\\Image\\Interfaces\\ImageInterface;\nuse Intervention\\Image\\Interfaces\\SpecializedInterface;\nuse Intervention\\Image\\Length;\nuse Intervention\\Image\\Resolution;\n\nclass ResolutionAnalyzer extends GenericResolutionAnalyzer implements SpecializedInterface\n{\n    /**\n     * @throws InvalidArgumentException\n     * @throws AnalyzerException\n     */\n    public function analyze(ImageInterface $image): mixed\n    {\n        $imagick = $image->core()->native();\n\n        try {\n            $imageResolution = $imagick->getImageResolution();\n        } catch (ImagickException $e) {\n            throw new AnalyzerException('Failed to read image resolution', previous: $e);\n        }\n\n        return new Resolution(\n            $imageResolution['x'],\n            $imageResolution['y'],\n            $imagick->getImageUnits() === 2 ? Length::CM : Length::INCH,\n        );\n    }\n}\n","sourceCodeStart":11,"sourceCodeEnd":39,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Analyzers/ResolutionAnalyzer.php#L11-L39","documentation":"$image->resolution() reads the DPI density via Imagick::getImageResolution(); an ImagickException there is wrapped into this AnalyzerException. Resolution metadata lives outside pixel data, so files with malformed or absent density records (some BMPs, aggregator-produced files, delegate-dependent formats) can trip the read even though pixels are fine.","triggerScenarios":"resolution() on files whose density chunk is corrupt or zeroed; on images processed by tools that wrote invalid resolution fields; querying resolution for formats whose ImageMagick delegate does not supply density (SVG, raw).","commonSituations":"Print-oriented pipelines reading DPI from arbitrary user uploads; mixed-format archives.","solutions":["Wrap resolution() in try/catch and default to 72 DPI when the metadata is unreadable.","If a specific DPI is required downstream, set it explicitly with $image->setResolution($x, $y) instead of trusting the file.","Inspect the odd file with identify -verbose to see whether a density record exists at all."],"exampleFix":"// before\n$resolution = $image->resolution();\n\n// after: default to 72 DPI when metadata is unreadable\ntry {\n    $resolution = $image->resolution();\n} catch (\\Intervention\\Image\\Exceptions\\AnalyzerException) {\n    $resolution = new \\Intervention\\Image\\Resolution(72, 72, \\Intervention\\Image\\Units\\Length::INCH);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { $resolution = $image->resolution(); } catch (AnalyzerException) { $resolution = new \\Intervention\\Image\\Resolution(72, 72, \\Intervention\\Image\\Units\\Length::INCH); }","preventionTips":["Treat DPI metadata as optional: always define a default resolution for your pipeline.","Set the required DPI explicitly with setResolution() when it matters downstream."],"tags":["imagick","resolution","dpi","metadata"],"backgroundTag":"corrupt-image-metadata","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}