Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException
Height must be greater than or equal to 1
Error message
Height must be greater than or equal to 1
What it means
The Resizer constructor rejects any integer height below 1. Height 0 or negative dimensions are considered invalid target sizes; pass null instead of 0 when you want the dimension to be auto-calculated. This guards the very first step of building a resize operation so that invalid geometry fails fast.
Source
Thrown at src/Geometry/Tools/Resizer.php:29
use Intervention\Image\Size;
class Resizer
{
/**
* @throws InvalidArgumentException
*/
public function __construct(
protected ?int $width = null,
protected ?int $height = null,
) {
if (is_int($width) && $width < 1) {
throw new InvalidArgumentException(
'Width must be greater than or equal to 1',
);
}
if (is_int($height) && $height < 1) {
throw new InvalidArgumentException(
'Height must be greater than or equal to 1',
);
}
}
/**
* Static factory method to create resizer with given target size.
*
* @throws InvalidArgumentException
*/
public static function to(?int $width = null, ?int $height = null): self
{
return new self($width, $height);
}
/**
* Determine if resize has target width.
*/View on GitHub (pinned to 5598b9e397)
Solutions
- Pass null instead of 0 for the height you want Intervention Image to calculate automatically: Resizer::to(300, null)
- If the height comes from user input or a calculation, clamp it: max(1, (int) $height)
- If you only want to set one dimension, use Resizer::to(300) and toHeight() later, or use the Image::scale()/resize() API which accepts null directly
- Check for sign errors in percentage/fraction math that produces 0 or negative heights
Example fix
// before $resizer = Resizer::to(300, 0); // throws InvalidArgumentException // after $resizer = Resizer::to(300, null); // height auto-calculated
Defensive patterns
Strategy: validation
Validate before calling
$height = $request->integer('height');
if ($height < 1) {
$height = null; // let the library auto-calculate
}
$resizer = Resizer::to(300, $height); Type guard
function isValidTargetDimension(?int $value): bool
{
return $value === null || $value >= 1;
} Try / catch
try {
$resizer = Resizer::to($w, $h);
} catch (InvalidArgumentException $e) {
// bad dimensions from user input: report 422, do not retry
} Prevention
- Treat null (not 0) as 'auto' in all dimension variables
- Clamp user-supplied dimensions with max(1, $value)
- Validate at the request boundary before building geometry objects
When it happens
Trigger: new Resizer($width, 0), new Resizer($width, -5), or Resizer::to(300, 0) — any call where the second constructor argument is an int < 1. The width check is identical (Resizer.php:22).
Common situations: Passing 0 meaning 'auto' or 'keep aspect ratio' (common when porting code from libraries where 0 means auto), or computing a height from user input / percentage math that evaluates to 0 or negative before the call.
Related errors
- Target size needs width and height
- Invalid target size
- Invalid image size
- Invalid image size. Must be int<1, max>
- Invalid image size. Must be int<1, max>
AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23).
Data as JSON: /api/errors/382327adceb9fe18.
Report an issue: GitHub.