{"record":{"id":"be186eb99014abc3","repo":"phalcon/cphalcon","slug":"width-and-height-must-be-specified","errorCode":null,"errorMessage":"Width and height must be specified","messagePattern":"Width and height must be specified","errorType":"exception","errorClass":"Phalcon\\Image\\Exceptions\\MissingDimensions","httpStatus":null,"severity":"error","filePath":"phalcon/Image/Adapter/AbstractAdapter.zep","lineNumber":573,"sourceCode":"        int opacity\n    ) -> void;\n    /**\n     * Resize the image to the given size\n     *\n     * @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(","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Image/Adapter/AbstractAdapter.zep#L555-L591","documentation":"Image\\Adapter\\AbstractAdapter::checkResizeInput() requires BOTH width and height when the resize master is AUTO (the default), TENSILE, INVERSE or PRECISE, because those modes compute the target geometry from both values. If either is null, MissingDimensions is thrown before any engine call.","triggerScenarios":"$image->resize(null, 600); resize(800, null); resize(null, null, Enum::INVERSE); - one or both dimensions omitted while a both-required master is in effect.","commonSituations":"Assuming the adapter infers the missing side from the aspect ratio (only WIDTH/HEIGHT masters do that); refactors that changed 0 to null; user input where one dimension field is empty.","solutions":["Pass both dimensions for AUTO/TENSILE/INVERSE/PRECISE: ->resize(800, 600);","When only one side is known, use the one-sided masters: ->resize(800, null, Enum::WIDTH) or ->resize(null, 600, Enum::HEIGHT)","Compute the missing side yourself from $image->getWidth()/getHeight() ratios before calling"],"exampleFix":"// before\n$image->resize(null, 600); // AUTO master needs both -> throws\n\n// after\n$image->resize(null, 600, \\Phalcon\\Image\\Enum::HEIGHT); // height-driven scaling","handlingStrategy":"validation","validationCode":"use Phalcon\\Image\\Enum;\n\n$bothRequired = [Enum::AUTO, Enum::TENSILE, Enum::INVERSE, Enum::PRECISE];\nif (in_array($master, $bothRequired, true) && (null === $width || null === $height)) {\n    throw new \\InvalidArgumentException('resize() needs both width and height for this master');\n}\n$image->resize($width, $height, $master);","typeGuard":"use Phalcon\\Image\\Enum;\n\nfunction resizeArgsComplete(?int $width, ?int $height, int $master): bool\n{\n    return match (true) {\n        in_array($master, [Enum::AUTO, Enum::TENSILE, Enum::INVERSE, Enum::PRECISE], true) => $width !== null && $height !== null,\n        $master === Enum::WIDTH => $width !== null,\n        $master === Enum::HEIGHT => $height !== null,\n        default => true,\n    };\n}","tryCatchPattern":"try { $image->resize($w, $h); } catch (\\Phalcon\\Image\\Exception $e) { // covers MissingDimensions/MissingWidth/MissingHeight\n    $image->resize($w ?? 800, $h ?? 800, \\Phalcon\\Image\\Enum::WIDTH); // recover with one-sided master\n}","preventionTips":["Choose the master constant consciously: WIDTH/HEIGHT when only one dimension is known","Never pass null dimensions with the default AUTO master","Derive missing sides from getImageWidth()/getImageHeight() ratios in your own code"],"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"}