{"record":{"id":"1142362faaf88d9f","repo":"Intervention/image","slug":"the-value-of-the-x-axis-for-class-must-be-greate","errorCode":null,"errorMessage":"The value of the X-axis for {class} must be greater or equal to 0","messagePattern":"The value of the X-axis for (.+?) must be greater or equal to 0","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Resolution.php","lineNumber":31,"sourceCode":"use Traversable;\n\n/**\n * @implements IteratorAggregate<float>\n */\nclass Resolution implements ResolutionInterface, Stringable, IteratorAggregate, JsonSerializable\n{\n    /**\n     * Create new instance.\n     *\n     * @throws InvalidArgumentException\n     */\n    public function __construct(\n        protected float $x,\n        protected float $y,\n        protected Length $length = Length::INCH,\n    ) {\n        if ($x < 0) {\n            throw new InvalidArgumentException(\n                'The value of the X-axis for ' . $this::class . ' must be greater or equal to 0',\n            );\n        }\n\n        if ($y < 0) {\n            throw new InvalidArgumentException(\n                'The value of the Y-axis for ' . $this::class . ' must be greater or equal to 0',\n            );\n        }\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see ResolutionInterface::dpi()\n     *\n     * @throws InvalidArgumentException\n     */","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Resolution.php#L13-L49","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass non-negative floats for the X-axis: abs() the value if it comes from untrusted metadata","Validate parsed image metadata before building a Resolution object","Fix the upstream calculation that produced a negative density"],"exampleFix":"// before\n$resolution = new Resolution(-72.0, 72.0);\n\n// after\n$resolution = new Resolution(abs($x), abs($y));","handlingStrategy":"validation","validationCode":"// Sanitize density values before constructing\n$x = abs((float) $metadata['x']);\n$y = abs((float) $metadata['y']);\n\n$resolution = new \\Intervention\\Image\\Resolution($x, $y);","typeGuard":"function isValidResolutionAxis(mixed $value): bool\n{\n    return (is_int($value) || is_float($value)) && $value >= 0.0;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $resolution = new Resolution($x, $y);\n} catch (InvalidArgumentException $e) {\n    // message names Resolution and the failing axis\n    $resolution = new Resolution(abs($x), abs($y));\n}","preventionTips":["Treat density values as unsigned floats in your data model","Sanitize metadata parsed from untrusted image files before building Resolution objects","The axis at fault is named in the exception message ('X-axis' vs 'Y-axis')"],"tags":["resolution","dpi","constructor","argument-validation","intervention-image"],"backgroundTag":"out-of-range-argument","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}