{"record":{"id":"73e25a6900416c79","repo":"Intervention/image","slug":"invalid-target-size-width-x-height-73e25a","errorCode":null,"errorMessage":"Invalid target size {width}x{height}","messagePattern":"Invalid target size (.+?)x(.+?)","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Size.php","lineNumber":304,"sourceCode":"     */\n    public function orientation(): Orientation\n    {\n        return Orientation::fromSize($this);\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see SizeInterface::resize()\n     *\n     * @throws InvalidArgumentException\n     */\n    public function resize(?int $width = null, ?int $height = null): SizeInterface\n    {\n        try {\n            return $this->resizer($width, $height)->resize($this);\n        } catch (InvalidArgumentException $e) {\n            throw new InvalidArgumentException(\n                'Invalid target size ' . $width . 'x' . $height,\n                previous: $e,\n            );\n        }\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see SizeInterface::resizeDown()\n     *\n     * @throws InvalidArgumentException\n     */\n    public function resizeDown(?int $width = null, ?int $height = null): SizeInterface\n    {\n        try {\n            return $this->resizer($width, $height)->resizeDown($this);\n        } catch (InvalidArgumentException $e) {","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Size.php#L286-L322","documentation":"Size::resize(width, height) delegates to the Resizer helper, whose constructor requires any non-null target dimension to be >= 1 (Resizer.php:22-32). When the Resizer rejects the input, Size::resize catches that InvalidArgumentException and rethrows it as 'Invalid target size {width}x{height}' with the original exception chained as previous, so the message always names the exact target that failed.","triggerScenarios":"Calling $size->resize(-1, -1), $size->resize(0, 300), or $size->resize(null, 0) — any target dimension that is a non-null int < 1. Equivalently via the image API, $image->resize(0, 300) reaches the same Resizer validation. Note that null/null is caught earlier by ResizeModifier's own check.","commonSituations":"Resize targets taken from user input where 0 means 'not provided'; arithmetic like width - padding that can drop below 1; percentage-based sizing that rounds a small image down to 0; API defaults of 0 used as 'unlimited'.","solutions":["Pass null instead of 0 for dimensions you want to be calculated automatically, and ensure passed ints are >= 1","Clamp computed targets: $width = max(1, (int) $width)","Validate resize parameters at the API boundary as positive integers"],"exampleFix":"// before\n$size->resize(0, 300); // 0 is not a valid target\n\n// after\n$size->resize(null, 300); // height-only resize, width auto","handlingStrategy":"validation","validationCode":"// Normalize resize targets: null = auto, ints must be >= 1\n$width = isset($input['width']) && $input['width'] > 0 ? (int) $input['width'] : null;\n$height = isset($input['height']) && $input['height'] > 0 ? (int) $input['height'] : null;\n\n$size->resize($width, $height);","typeGuard":"function isValidResizeTarget(null|int $value): bool\n{\n    return $value === null || $value >= 1;\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $size->resize($width, $height);\n} catch (InvalidArgumentException $e) {\n    // message: 'Invalid target size {width}x{height}' — inspect $e->getPrevious() for the root cause\n    $size->resize(null, max(1, (int) $height));\n}","preventionTips":["Use null (not 0) to mean 'auto' for a dimension","Validate resize parameters as null-or-positive-int at the API boundary","The chained previous exception tells you whether width or height was rejected"],"tags":["size","resize","dimensions","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"}