Intervention/image · error · InvalidArgumentException

The value of the Y-axis for {class} must be greater or equal

Error message

The value of the Y-axis for {class} must be greater or equal to 0

What it means

Resolution represents the pixel density (e.g. DPI) of an image along two axes and is normally produced by the drivers' ResolutionAnalyzer from image metadata. Its constructor requires the Y-axis value to be a float >= 0; a negative density has no physical meaning, so InvalidArgumentException is thrown naming the offending class (Resolution). This is the Y-axis sibling of the X-axis check that runs just before it in the same constructor.

Source

Thrown at src/Resolution.php:37

{
    /**
     * Create new instance.
     *
     * @throws InvalidArgumentException
     */
    public function __construct(
        protected float $x,
        protected float $y,
        protected Length $length = Length::INCH,
    ) {
        if ($x < 0) {
            throw new InvalidArgumentException(
                'The value of the X-axis for ' . $this::class . ' must be greater or equal to 0',
            );
        }

        if ($y < 0) {
            throw new InvalidArgumentException(
                'The value of the Y-axis for ' . $this::class . ' must be greater or equal to 0',
            );
        }
    }

    /**
     * {@inheritdoc}
     *
     * @see ResolutionInterface::dpi()
     *
     * @throws InvalidArgumentException
     */
    public static function dpi(float $x, float $y): ResolutionInterface
    {
        return new self($x, $y, Length::INCH);
    }

    /**

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Pass non-negative floats for the Y-axis: abs() the value if it comes from untrusted metadata
  2. Validate parsed image metadata before building a Resolution object
  3. Fix the upstream calculation that produced a negative density

Example fix

// before
$resolution = new Resolution(72.0, -72.0);

// after
$resolution = new Resolution(abs($x), abs($y));
Defensive patterns

Strategy: validation

Validate before calling

// Sanitize density values before constructing
$x = abs((float) $metadata['x']);
$y = abs((float) $metadata['y']);

$resolution = new \Intervention\Image\Resolution($x, $y);

Type guard

function isValidResolutionAxis(mixed $value): bool
{
    return (is_int($value) || is_float($value)) && $value >= 0.0;
}

Try / catch

use Intervention\Image\Exceptions\InvalidArgumentException;

try {
    $resolution = new Resolution($x, $y);
} catch (InvalidArgumentException $e) {
    // message names Resolution and the failing axis
    $resolution = new Resolution(abs($x), abs($y));
}

Prevention

When it happens

Trigger: Constructing new Resolution(72.0, -72.0) directly; passing a negative Y density from a calculation or from corrupt parsed metadata; unit tests using negative literals for both axes.

Common situations: Copy/paste or unit-conversion mistakes that introduce a minus sign; storing resolution in config and later multiplying by a direction factor; test fixtures with negative numbers; metadata from damaged or hand-edited image files.

Related errors


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