{"record":{"id":"11ca2d5463a1bbd0","repo":"Intervention/image","slug":"failed-to-apply-class-unable-to-set-image-resol","errorCode":null,"errorMessage":"Failed to apply {class}, unable to set image resolution","messagePattern":"Failed to apply (.+?), unable to set image resolution","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/ResolutionModifier.php","lineNumber":25,"sourceCode":"use ImagickException;\nuse Intervention\\Image\\Exceptions\\ModifierException;\nuse Intervention\\Image\\Interfaces\\ImageInterface;\nuse Intervention\\Image\\Interfaces\\SpecializedInterface;\nuse Intervention\\Image\\Modifiers\\ResolutionModifier as GenericResolutionModifier;\n\nclass ResolutionModifier extends GenericResolutionModifier implements SpecializedInterface\n{\n    /**\n     * @throws ModifierException\n     */\n    public function apply(ImageInterface $image): ImageInterface\n    {\n        $imagick = $image->core()->native();\n\n        try {\n            $result = $imagick->setImageResolution($this->x, $this->y);\n            if ($result === false) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to set image resolution',\n                );\n            }\n        } catch (ImagickException $e) {\n            throw new ModifierException(\n                'Failed to apply ' . self::class . ', unable to set image resolution',\n                previous: $e,\n            );\n        }\n\n        return $image;\n    }\n}\n","sourceCodeStart":7,"sourceCodeEnd":39,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/ResolutionModifier.php#L7-L39","documentation":"setResolution() forwards the DPI values to Imagick::setImageResolution($x, $y); a false return triggers this ModifierException. The generic ResolutionModifier constructor stores the floats without validating them, so zero or negative resolutions reach ImageMagick, which requires strictly positive values. This false-return branch is the rarer path; invalid resolutions more often throw ImagickException (sibling catch).","triggerScenarios":"$image->setResolution(0, 72), setResolution(-1, -1), or DPI values computed from user input / EXIF / PDF metadata that can be 0.","commonSituations":"Export code copying resolution from a source whose metadata is missing (defaults to 0); PDF/EPS workflows where 0 DPI sneaks in; forms letting users type 0 into a DPI field.","solutions":["Validate before calling: both x and y must be > 0","Default missing metadata to a sane DPI (72 for screen, 300 for print) instead of 0","Enforce numeric bounds (min:0.01 or min:1) on user-supplied DPI at the request boundary","If the call still fails, inspect the chained previous exception for the native wording"],"exampleFix":"// before\n$image->setResolution($sourceDpi, $sourceDpi); // 0 when metadata absent\n\n// after\n$dpi = $sourceDpi > 0 ? $sourceDpi : 72.0;\n$image->setResolution($dpi, $dpi);","handlingStrategy":"validation","validationCode":"if ($x <= 0 || $y <= 0) {\n    throw new \\InvalidArgumentException(sprintf('Resolution must be positive, got %F x %F', $x, $y));\n}\n$image->setResolution($x, $y);","typeGuard":"function isValidResolution(float $x, float $y): bool\n{\n    return $x > 0 && $y > 0;\n}","tryCatchPattern":null,"preventionTips":["Default missing DPI metadata to 72 (screen) or 300 (print) instead of letting 0 through","Validate DPI form fields with numeric min:1 rules","Remember the library does not pre-validate x/y; the caller owns this invariant"],"tags":["php","imagick","intervention-image","resolution","dpi","input-validation"],"backgroundTag":"image-resolution-set-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}