Intervention/image · error · InvalidArgumentException

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

Error message

The value of the X-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 X-axis value to be a float >= 0; a negative density has no physical meaning, so InvalidArgumentException is thrown naming the offending class (Resolution).

Source

Thrown at src/Resolution.php:31

use Traversable;

/**
 * @implements IteratorAggregate<float>
 */
class Resolution implements ResolutionInterface, Stringable, IteratorAggregate, JsonSerializable
{
    /**
     * 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
     */

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Pass non-negative floats for the X-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 sign-flipped or computed negative density value into code that builds a Resolution; feeding manually parsed or corrupt image metadata containing negative resolution values.

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/1142362faaf88d9f. Report an issue: GitHub.