Intervention/image · error · InvalidArgumentException
Height of must be greater than or equal to 0
Error message
Height of {class} must be greater than or equal to 0 What it means
Size is the core width/height/pivot value object used throughout the library for image and crop dimensions. Its constructor requires height to be an int >= 0 (0 is allowed); a negative height is rejected with InvalidArgumentException naming the class. This is the height sibling of the width check that runs just before it in the same constructor.
Solutions
- Validate dimensions as int >= 0 before constructing Size
- Use abs() or reorder coordinates when a delta is legitimately invertible
- Reject or clamp negative dimensions at the API boundary before they reach geometry code
Example fix
// before $size = new Size($x2 - $x1, $y2 - $y1); // negative when y2 < y1 // after $size = new Size(abs($x2 - $x1), abs($y2 - $y1));
Defensive patterns
Strategy: validation
Validate before calling
// Validate dimensions before building geometry $width = max(0, (int) $input['width']); $height = max(0, (int) $input['height']); $size = new \Intervention\Image\Size($width, $height);
Type guard
function isValidDimension(mixed $value): bool
{
return is_int($value) && $value >= 0;
} Try / catch
use Intervention\Image\Exceptions\InvalidArgumentException;
try {
$size = new Size($width, $height);
} catch (InvalidArgumentException $e) {
// message: 'Height of ... must be greater than or equal to 0'
$size = new Size(abs($width), abs($height));
} Prevention
- Validate width/height as non-negative ints wherever user input enters geometry code
- Normalize crop rectangles by ordering coordinates (min/max) before subtracting
- The exception message names the failing axis ('Width' vs 'Height')
When it happens
Trigger: Constructing new Size(100, -50); building crop/resize geometry from user input where height is negative; passing a computed dimension like $bottom - $top that can go negative when the rectangle is inverted.
Common situations: Crop coordinates where the user swaps y1/y2 so the delta becomes negative; image-processing pipelines fed with unvalidated request data; math that assumes an ordering (e.g. larger minus smaller) that the input violates.
Related errors
- Width of must be greater than or equal to 0
- At least one argument must be provided: width, height, or…
- Invalid target size x
- 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/08ff66027b47825e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Size.php:43
{
/**
* Create new size instance.
*
* @throws InvalidArgumentException
*/
public function __construct(
protected int $width,
protected int $height,
protected PointInterface $pivot = new Point(),
) {
if ($width < 0) {
throw new InvalidArgumentException(
'Width of ' . $this::class . ' must be greater than or equal to 0',
);
}
if ($height < 0) {
throw new InvalidArgumentException(
'Height of ' . $this::class . ' must be greater than or equal to 0',
);
}
}
/**
* Create size statically.
*
* @throws InvalidArgumentException
*/
public static function create(int $width, int $height, PointInterface $pivot = new Point()): self
{
return new self($width, $height, $pivot);
}
/**
* {@inheritdoc}
*View on GitHub (pinned to 5598b9e397)