phalcon/cphalcon · error · Phalcon\Image\Exceptions\MissingWidth
Width must be specified
Error message
Width must be specified
What it means
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).
Source
Thrown at phalcon/Image/Adapter/AbstractAdapter.zep:578
* @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(
int width = null,
int height = null,
int master = Enum::AUTO
) -> int {
if (master === Enum::AUTO) {View on GitHub (pinned to b7419de9cd)
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);
Example fix
// before $image->resize(null, 600, \Phalcon\Image\Enum::WIDTH); // throws MissingWidth // after $image->resize(800, null, \Phalcon\Image\Enum::WIDTH); // height derived
Defensive patterns
Strategy: validation
Validate before calling
use Phalcon\Image\Enum;
if (Enum::WIDTH === $master && null === $width) {
throw new \InvalidArgumentException('WIDTH master requires a width');
}
$image->resize($width, $height, $master); Type guard
function hasRequiredWidth(?int $width, int $master): bool
{
return \Phalcon\Image\Enum::WIDTH !== $master || $width !== null;
} Try / catch
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
} Prevention
- 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
When it happens
Trigger: $image->resize(null, 600, Enum::WIDTH); - width omitted while the WIDTH master is selected.
Common situations: 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.
Related errors
- Width and height 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/5a768b026e3f571a.
Report an issue: GitHub.