{"record":{"id":"464901df10047a5b","repo":"Intervention/image","slug":"the-value-of-the-y-axis-for-class-must-be-greate","errorCode":null,"errorMessage":"The value of the Y-axis for {class} must be greater or equal to 0","messagePattern":"The value of the Y-axis for (.+?) must be greater or equal to 0","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Resolution.php","lineNumber":37,"sourceCode":"{\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     */\n    public static function dpi(float $x, float $y): ResolutionInterface\n    {\n        return new self($x, $y, Length::INCH);\n    }\n\n    /**","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Resolution.php#L19-L55","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 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.","triggerScenarios":"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.","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 Y-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"}