{"record":{"id":"8acd97e0f3e29aa8","repo":"Intervention/image","slug":"at-least-one-argument-must-be-provided-width-hei","errorCode":null,"errorMessage":"At least one argument must be provided: width, height, or both.","messagePattern":"At least one argument must be provided: width, height, or both\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Modifiers/ResizeModifier.php","lineNumber":20,"sourceCode":"\ndeclare(strict_types=1);\n\nnamespace Intervention\\Image\\Modifiers;\n\nuse Intervention\\Image\\Drivers\\SpecializableModifier;\nuse Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\nclass ResizeModifier extends SpecializableModifier\n{\n    /**\n     * Create new modifier object.\n     *\n     * @throws InvalidArgumentException\n     */\n    public function __construct(public ?int $width = null, public ?int $height = null)\n    {\n        if ($width === null && $height === null) {\n            throw new InvalidArgumentException('At least one argument must be provided: width, height, or both.');\n        }\n    }\n}\n","sourceCodeStart":2,"sourceCodeEnd":24,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Modifiers/ResizeModifier.php#L2-L24","documentation":"ResizeModifier is the object behind $image->resize(), $image->resizeDown(), $image->scale() and $image->scaleDown() (ResizeDownModifier and ScaleModifier extend ResizeModifier). Its constructor allows width and height to be nullable individually, but at least one non-null integer must be given, because with both null there is no target size to resize to. When both arguments are null it throws InvalidArgumentException immediately at construction time.","triggerScenarios":"Calling $image->resize(null, null) (or resizeDown/scale/scaleDown with both null), or new ResizeModifier(null, null) directly. Typically both values come from user input or config and both resolve to null, e.g. $image->resize($request->query('w'), $request->query('h')) when neither query parameter is present.","commonSituations":"Thumbnail endpoints where width/height are optional request parameters and a request omits both; config-driven pipelines where a feature flag or profile nulls out both dimensions; refactors that changed defaults from a fixed number to null; dynamic code that computes one dimension from the other and passes null for both by mistake.","solutions":["Pass at least one of width or height, e.g. $image->resize(null, 300) to set only the height","If dimensions come from user input, validate before calling: if (empty($width) && empty($height)) { abort or apply a default }","Apply a fallback default dimension (e.g. a configured thumbnail width) when both inputs are missing","If you want proportional behavior with no explicit target, skip the resize call entirely instead of passing null/null"],"exampleFix":"// before\n$image->resize($request->query('w'), $request->query('h'));\n\n// after\n$width = $request->query('w') ? (int) $request->query('w') : null;\n$height = $request->query('h') ? (int) $request->query('h') : null;\n$image->resize($width, $height ?? 300); // always at least one dimension","handlingStrategy":"validation","validationCode":"// Before resizing, ensure at least one dimension is set\n$width = isset($input['width']) ? (int) $input['width'] : null;\n$height = isset($input['height']) ? (int) $input['height'] : null;\n\nif ($width === null && $height === null) {\n    $height = 300; // sensible default instead of throwing\n}\n\n$image->resize($width, $height);","typeGuard":"/** @param array{width?:int|string|null,height?:int|string|null} $input */\nfunction hasResizeTarget(array $input): bool\n{\n    return isset($input['width']) || isset($input['height']);\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $image->resize($width, $height);\n} catch (InvalidArgumentException $e) {\n    // $e->getMessage() === 'At least one argument must be provided: width, height, or both.'\n    $image->resize(null, 300); // retry with a default dimension\n}","preventionTips":["Never pass two nulls to resize()/resizeDown()/scale()/scaleDown(); default at least one dimension at the call site","Centralize dimension parsing from requests/config in one helper that guarantees a non-null value","Treat 'both dimensions missing' as a validation error in your API layer, not a library concern"],"tags":["resize","constructor","argument-validation","dimensions","intervention-image"],"backgroundTag":"missing-required-argument","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}