phalcon/cphalcon · error · Phalcon\Image\Exceptions\MissingDimensions
Width and height must be specified
Error message
Width and height must be specified
What it means
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.
Source
Thrown at phalcon/Image/Adapter/AbstractAdapter.zep:573
int opacity
) -> void;
/**
* Resize the image to the given size
*
* @throws Exception
*/
private function checkResizeInput(
int width = null,
int height = null,
int master = Enum::AUTO
) -> void {
switch master {
case Enum::TENSILE:
case Enum::AUTO:
case Enum::INVERSE:
case Enum::PRECISE:
if (null === width || null === height) {
throw new MissingDimensions();
}
break;
case Enum::WIDTH:
if (null === width) {
throw new MissingWidth();
}
break;
case Enum::HEIGHT:
if (null === height) {
throw new MissingHeight();
}
break;
default:
break;
}
}
private function checkResizeMaster(View on GitHub (pinned to b7419de9cd)
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
Example fix
// before $image->resize(null, 600); // AUTO master needs both -> throws // after $image->resize(null, 600, \Phalcon\Image\Enum::HEIGHT); // height-driven scaling
Defensive patterns
Strategy: validation
Validate before calling
use Phalcon\Image\Enum;
$bothRequired = [Enum::AUTO, Enum::TENSILE, Enum::INVERSE, Enum::PRECISE];
if (in_array($master, $bothRequired, true) && (null === $width || null === $height)) {
throw new \InvalidArgumentException('resize() needs both width and height for this master');
}
$image->resize($width, $height, $master); Type guard
use Phalcon\Image\Enum;
function resizeArgsComplete(?int $width, ?int $height, int $master): bool
{
return match (true) {
in_array($master, [Enum::AUTO, Enum::TENSILE, Enum::INVERSE, Enum::PRECISE], true) => $width !== null && $height !== null,
$master === Enum::WIDTH => $width !== null,
$master === Enum::HEIGHT => $height !== null,
default => true,
};
} Try / catch
try { $image->resize($w, $h); } catch (\Phalcon\Image\Exception $e) { // covers MissingDimensions/MissingWidth/MissingHeight
$image->resize($w ?? 800, $h ?? 800, \Phalcon\Image\Enum::WIDTH); // recover with one-sided master
} Prevention
- 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
When it happens
Trigger: $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.
Common situations: 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.
Related errors
- Width must be specified
- Height must be specified
- The color '{color}' is not a valid hex color
- Failed to create image from file {file}
- Installed GD does not support {mime} images
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/be186eb99014abc3.
Report an issue: GitHub.