Intervention/image · error · InvalidArgumentException
At least one argument must be provided: width, height, or…
Error message
At least one argument must be provided: width, height, or both.
What it means
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.
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
Example fix
// before
$image->resize($request->query('w'), $request->query('h'));
// after
$width = $request->query('w') ? (int) $request->query('w') : null;
$height = $request->query('h') ? (int) $request->query('h') : null;
$image->resize($width, $height ?? 300); // always at least one dimension Defensive patterns
Strategy: validation
Validate before calling
// Before resizing, ensure at least one dimension is set
$width = isset($input['width']) ? (int) $input['width'] : null;
$height = isset($input['height']) ? (int) $input['height'] : null;
if ($width === null && $height === null) {
$height = 300; // sensible default instead of throwing
}
$image->resize($width, $height); Type guard
/** @param array{width?:int|string|null,height?:int|string|null} $input */
function hasResizeTarget(array $input): bool
{
return isset($input['width']) || isset($input['height']);
} Try / catch
use Intervention\Image\Exceptions\InvalidArgumentException;
try {
$image->resize($width, $height);
} catch (InvalidArgumentException $e) {
// $e->getMessage() === 'At least one argument must be provided: width, height, or both.'
$image->resize(null, 300); // retry with a default dimension
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Height of must be greater than or equal to 0
- Invalid target size x
- Width of must be greater than or equal to 0
- Invalid sharpening level. Must be int<0, max>
- Invalid trim tolerance. Must be int<0, max>
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/8acd97e0f3e29aa8.
Report an issue: GitHub.
Appendix: source
Thrown at src/Modifiers/ResizeModifier.php:20
declare(strict_types=1);
namespace Intervention\Image\Modifiers;
use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\InvalidArgumentException;
class ResizeModifier extends SpecializableModifier
{
/**
* Create new modifier object.
*
* @throws InvalidArgumentException
*/
public function __construct(public ?int $width = null, public ?int $height = null)
{
if ($width === null && $height === null) {
throw new InvalidArgumentException('At least one argument must be provided: width, height, or both.');
}
}
}
View on GitHub (pinned to 5598b9e397)