{"record":{"id":"08ff66027b47825e","repo":"Intervention/image","slug":"height-of-class-must-be-greater-than-or-equal-to","errorCode":null,"errorMessage":"Height of {class} must be greater than or equal to 0","messagePattern":"Height of (.+?) must be greater than or equal to 0","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Size.php","lineNumber":43,"sourceCode":"{\n    /**\n     * Create new size instance.\n     *\n     * @throws InvalidArgumentException\n     */\n    public function __construct(\n        protected int $width,\n        protected int $height,\n        protected PointInterface $pivot = new Point(),\n    ) {\n        if ($width < 0) {\n            throw new InvalidArgumentException(\n                'Width of ' . $this::class . ' must be greater than or equal to 0',\n            );\n        }\n\n        if ($height < 0) {\n            throw new InvalidArgumentException(\n                'Height of ' . $this::class . ' must be greater than or equal to 0',\n            );\n        }\n    }\n\n    /**\n     * Create size statically.\n     *\n     * @throws InvalidArgumentException\n     */\n    public static function create(int $width, int $height, PointInterface $pivot = new Point()): self\n    {\n        return new self($width, $height, $pivot);\n    }\n\n    /**\n     * {@inheritdoc}\n     *","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Size.php#L25-L61","documentation":"Size is the core width/height/pivot value object used throughout the library for image and crop dimensions. Its constructor requires height to be an int >= 0 (0 is allowed); a negative height is rejected with InvalidArgumentException naming the class. This is the height sibling of the width check that runs just before it in the same constructor.","triggerScenarios":"Constructing new Size(100, -50); building crop/resize geometry from user input where height is negative; passing a computed dimension like $bottom - $top that can go negative when the rectangle is inverted.","commonSituations":"Crop coordinates where the user swaps y1/y2 so the delta becomes negative; image-processing pipelines fed with unvalidated request data; math that assumes an ordering (e.g. larger minus smaller) that the input violates.","solutions":["Validate dimensions as int >= 0 before constructing Size","Use abs() or reorder coordinates when a delta is legitimately invertible","Reject or clamp negative dimensions at the API boundary before they reach geometry code"],"exampleFix":"// before\n$size = new Size($x2 - $x1, $y2 - $y1); // negative when y2 < y1\n\n// after\n$size = new Size(abs($x2 - $x1), abs($y2 - $y1));","handlingStrategy":"validation","validationCode":"// Validate dimensions before building geometry\n$width = max(0, (int) $input['width']);\n$height = max(0, (int) $input['height']);\n\n$size = new \\Intervention\\Image\\Size($width, $height);","typeGuard":"function isValidDimension(mixed $value): bool\n{\n    return is_int($value) && $value >= 0;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $size = new Size($width, $height);\n} catch (InvalidArgumentException $e) {\n    // message: 'Height of ... must be greater than or equal to 0'\n    $size = new Size(abs($width), abs($height));\n}","preventionTips":["Validate width/height as non-negative ints wherever user input enters geometry code","Normalize crop rectangles by ordering coordinates (min/max) before subtracting","The exception message names the failing axis ('Width' vs 'Height')"],"tags":["size","dimensions","constructor","argument-validation","intervention-image"],"backgroundTag":"invalid-image-dimensions","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}