{"record":{"id":"5a768b026e3f571a","repo":"phalcon/cphalcon","slug":"width-must-be-specified","errorCode":null,"errorMessage":"Width must be specified","messagePattern":"Width must be specified","errorType":"exception","errorClass":"Phalcon\\Image\\Exceptions\\MissingWidth","httpStatus":null,"severity":"error","filePath":"phalcon/Image/Adapter/AbstractAdapter.zep","lineNumber":578,"sourceCode":"     * @throws Exception\n     */\n    private function checkResizeInput(\n        int width = null,\n        int height = null,\n        int master = Enum::AUTO\n    ) -> void {\n        switch master {\n            case Enum::TENSILE:\n            case Enum::AUTO:\n            case Enum::INVERSE:\n            case Enum::PRECISE:\n                if (null === width || null === height) {\n                    throw new MissingDimensions();\n                }\n                break;\n            case Enum::WIDTH:\n                if (null === width) {\n                    throw new MissingWidth();\n                }\n                break;\n            case Enum::HEIGHT:\n                if (null === height) {\n                    throw new MissingHeight();\n                }\n                break;\n            default:\n                break;\n        }\n    }\n\n    private function checkResizeMaster(\n        int width = null,\n        int height = null,\n        int master = Enum::AUTO\n    ) -> int {\n        if (master === Enum::AUTO) {","sourceCodeStart":560,"sourceCodeEnd":596,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Image/Adapter/AbstractAdapter.zep#L560-L596","documentation":"With master = Phalcon\\Image\\Enum::WIDTH the adapter scales the image proportionally based on the given width, so width is mandatory; a null width throws MissingWidth (the height value is derived and ignored).","triggerScenarios":"$image->resize(null, 600, Enum::WIDTH); - width omitted while the WIDTH master is selected.","commonSituations":"Swapping argument order relative to the master constant; dynamic width values (e.g. from request input) arriving null; copying a HEIGHT example and changing only the master.","solutions":["Supply the width: ->resize(800, null, Enum::WIDTH);","If only the height is known, switch master: ->resize(null, 600, Enum::HEIGHT);","Default the width from the source image: ->resize($image->getWidth(), null, Enum::WIDTH);"],"exampleFix":"// before\n$image->resize(null, 600, \\Phalcon\\Image\\Enum::WIDTH); // throws MissingWidth\n\n// after\n$image->resize(800, null, \\Phalcon\\Image\\Enum::WIDTH); // height derived","handlingStrategy":"validation","validationCode":"use Phalcon\\Image\\Enum;\n\nif (Enum::WIDTH === $master && null === $width) {\n    throw new \\InvalidArgumentException('WIDTH master requires a width');\n}\n$image->resize($width, $height, $master);","typeGuard":"function hasRequiredWidth(?int $width, int $master): bool\n{\n    return \\Phalcon\\Image\\Enum::WIDTH !== $master || $width !== null;\n}","tryCatchPattern":"try { $image->resize($w, $h, \\Phalcon\\Image\\Enum::WIDTH); } catch (\\Phalcon\\Image\\Exceptions\\MissingWidth $e) { $image->resize($image->getWidth(), null, \\Phalcon\\Image\\Enum::WIDTH); // fall back to source width\n}","preventionTips":["Double-check argument order versus the master constant","Default null width from the source image or user setting before calling","Use Enum::HEIGHT when the height is the only known value"],"tags":["php","phalcon","image","gd","validation"],"backgroundTag":"missing-image-dimensions","analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}