{"record":{"id":"382327adceb9fe18","repo":"Intervention/image","slug":"height-must-be-greater-than-or-equal-to-1","errorCode":null,"errorMessage":"Height must be greater than or equal to 1","messagePattern":"Height must be greater than or equal to 1","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Geometry/Tools/Resizer.php","lineNumber":29,"sourceCode":"use Intervention\\Image\\Size;\n\nclass Resizer\n{\n    /**\n     * @throws InvalidArgumentException\n     */\n    public function __construct(\n        protected ?int $width = null,\n        protected ?int $height = null,\n    ) {\n        if (is_int($width) && $width < 1) {\n            throw new InvalidArgumentException(\n                'Width must be greater than or equal to 1',\n            );\n        }\n\n        if (is_int($height) && $height < 1) {\n            throw new InvalidArgumentException(\n                'Height must be greater than or equal to 1',\n            );\n        }\n    }\n\n    /**\n     * Static factory method to create resizer with given target size.\n     *\n     * @throws InvalidArgumentException\n     */\n    public static function to(?int $width = null, ?int $height = null): self\n    {\n        return new self($width, $height);\n    }\n\n    /**\n     * Determine if resize has target width.\n     */","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Geometry/Tools/Resizer.php#L11-L47","documentation":"The Resizer constructor rejects any integer height below 1. Height 0 or negative dimensions are considered invalid target sizes; pass null instead of 0 when you want the dimension to be auto-calculated. This guards the very first step of building a resize operation so that invalid geometry fails fast.","triggerScenarios":"new Resizer($width, 0), new Resizer($width, -5), or Resizer::to(300, 0) — any call where the second constructor argument is an int < 1. The width check is identical (Resizer.php:22).","commonSituations":"Passing 0 meaning 'auto' or 'keep aspect ratio' (common when porting code from libraries where 0 means auto), or computing a height from user input / percentage math that evaluates to 0 or negative before the call.","solutions":["Pass null instead of 0 for the height you want Intervention Image to calculate automatically: Resizer::to(300, null)","If the height comes from user input or a calculation, clamp it: max(1, (int) $height)","If you only want to set one dimension, use Resizer::to(300) and toHeight() later, or use the Image::scale()/resize() API which accepts null directly","Check for sign errors in percentage/fraction math that produces 0 or negative heights"],"exampleFix":"// before\n$resizer = Resizer::to(300, 0); // throws InvalidArgumentException\n\n// after\n$resizer = Resizer::to(300, null); // height auto-calculated","handlingStrategy":"validation","validationCode":"$height = $request->integer('height');\nif ($height < 1) {\n    $height = null; // let the library auto-calculate\n}\n$resizer = Resizer::to(300, $height);","typeGuard":"function isValidTargetDimension(?int $value): bool\n{\n    return $value === null || $value >= 1;\n}","tryCatchPattern":"try {\n    $resizer = Resizer::to($w, $h);\n} catch (InvalidArgumentException $e) {\n    // bad dimensions from user input: report 422, do not retry\n}","preventionTips":["Treat null (not 0) as 'auto' in all dimension variables","Clamp user-supplied dimensions with max(1, $value)","Validate at the request boundary before building geometry objects"],"tags":["geometry","resizer","validation","dimensions"],"backgroundTag":"invalid-image-dimensions","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}