{"record":{"id":"02205daf8d49cc67","repo":"Intervention/image","slug":"failed-to-apply-class-unable-to-process-resizin","errorCode":null,"errorMessage":"Failed to apply {class}, unable to process resizing","messagePattern":"Failed to apply (.+?), unable to process resizing","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\ModifierException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Imagick/Modifiers/ResizeModifier.php","lineNumber":30,"sourceCode":"use Intervention\\Image\\Modifiers\\ResizeModifier as GenericResizeModifier;\n\nclass ResizeModifier extends GenericResizeModifier implements SpecializedInterface\n{\n    /**\n     * @throws ModifierException\n     */\n    public function apply(ImageInterface $image): ImageInterface\n    {\n        $resizeTo = $this->adjustedSize($image);\n\n        foreach ($image as $frame) {\n            try {\n                $frame->native()->scaleImage(\n                    $resizeTo->width(),\n                    $resizeTo->height(),\n                );\n            } catch (ImagickException $e) {\n                throw new ModifierException(\n                    'Failed to apply ' . self::class . ', unable to process resizing',\n                    previous: $e,\n                );\n            }\n        }\n\n        return $image;\n    }\n\n    protected function adjustedSize(ImageInterface $image): SizeInterface\n    {\n        return $image->size()->resize($this->width, $this->height);\n    }\n}\n","sourceCodeStart":12,"sourceCodeEnd":45,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Imagick/Modifiers/ResizeModifier.php#L12-L45","documentation":"resize() computes the target size via adjustedSize() and calls Imagick::scaleImage($w, $h) per frame; this driver wraps any ImagickException into a ModifierException with the original chained. Unlike the other modifiers there is no false-return check here because scaleImage failures surface as exceptions. The dominant native causes are 'Invalid image geometry' when the computed target has a zero dimension and policy/memory errors when the target is huge.","triggerScenarios":"$image->resize(0, 0) or computing a size that collapses to 0 (e.g. Fraction/percentage math on tiny images); $image->resize(20000, 20000) upscaling beyond policy.xml width/height/area caps; memory exhaustion scaling a large frame up.","commonSituations":"Thumbnail code passing user-controlled width/height that can be 0; shared hosts capping ImageMagick area so big upscales are denied; Percentage/Fraction-based resizes on 1px images rounding to 0.","solutions":["Validate dimensions before resizing: both target dimensions must be >= 1 after computation","Check $e->getPrevious()?->getMessage(): 'Invalid image geometry' -> zero dimension, 'exceeds limit' -> policy.xml, memory wording -> raise limits","Raise policy.xml width/height/area limits or memory_limit if legitimate large outputs are intended","Downscale (or cap) user-supplied sizes at the request boundary so targets stay inside your resource envelope"],"exampleFix":"// before\n$image->resize($request->integer('w'), $request->integer('h')); // 0s pass through\n\n// after\n$w = max(1, min(4096, $request->integer('w', 100)));\n$h = max(1, min(4096, $request->integer('h', 100)));\n$image->resize($w, $h);","handlingStrategy":"try-catch","validationCode":"$w = (int) $request->integer('w', 0);\n$h = (int) $request->integer('h', 0);\nif ($w < 1 && $h < 1) {\n    throw new \\InvalidArgumentException('Resize needs at least one positive dimension');\n}\nif ($w !== 0) { $w = max(1, min(8192, $w)); }\nif ($h !== 0) { $h = max(1, min(8192, $h)); }\n$image->resize($w, $h);","typeGuard":null,"tryCatchPattern":"use Intervention\\Image\\Exceptions\\ModifierException;\n\ntry {\n    $image->resize($w, $h);\n} catch (ModifierException $e) {\n    $msg = $e->getPrevious()?->getMessage() ?? '';\n    if (str_contains($msg, 'geometry')) {\n        // zero target dimension: recompute with positive fallbacks\n    } elseif (str_contains($msg, 'limit')) {\n        // policy cap: clamp target size and retry\n    } else {\n        throw $e;\n    }\n}","preventionTips":["Never pass raw user width/height into resize(); clamp to >= 1 and a sane maximum first","Know your host's policy.xml width/height/area caps and cap resize targets below them","Watch Fraction/percentage-based sizes on tiny images; they can round down to a zero dimension"],"tags":["php","imagick","intervention-image","resize","scaleimage","invalid-image-geometry"],"backgroundTag":"image-resize-failed","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}