Intervention/image · error · InvalidArgumentException

At least one argument must be provided: width, height, or bo

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.

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)

Solutions

  1. Pass at least one of width or height, e.g. $image->resize(null, 300) to set only the height
  2. If dimensions come from user input, validate before calling: if (empty($width) && empty($height)) { abort or apply a default }
  3. Apply a fallback default dimension (e.g. a configured thumbnail width) when both inputs are missing
  4. 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

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


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/8acd97e0f3e29aa8. Report an issue: GitHub.