phalcon/cphalcon · error · Phalcon\Image\Exceptions\MissingHeight

Height must be specified

Error message

Height must be specified

What it means

Thrown by the image adapter resize logic when master mode is TENSILE, AUTO, INVERSE or PRECISE and either width or height is null; these modes require both dimensions to compute the new size. Supply both width and height, or use a master mode that needs only one.

Solutions

  1. Supply the height: ->resize(null, 600, Enum::HEIGHT);
  2. Use Enum::WIDTH when only the width is known
  3. Default the height from the source image: ->resize(null, $image->getHeight(), Enum::HEIGHT);

Example fix

// before
$image->resize(800, null, \Phalcon\Image\Enum::HEIGHT); // throws MissingHeight

// after
$image->resize(null, 600, \Phalcon\Image\Enum::HEIGHT); // width derived
Defensive patterns

Strategy: validation

Validate before calling

use Phalcon\Image\Enum;

if (Enum::HEIGHT === $master && null === $height) {
    throw new \InvalidArgumentException('HEIGHT master requires a height');
}
$image->resize($width, $height, $master);

Type guard

function hasRequiredHeight(?int $height, int $master): bool
{
    return \Phalcon\Image\Enum::HEIGHT !== $master || $height !== null;
}

Try / catch

try { $image->resize($w, $h, \Phalcon\Image\Enum::HEIGHT); } catch (\Phalcon\Image\Exceptions\MissingHeight $e) { $image->resize(null, $image->getHeight(), \Phalcon\Image\Enum::HEIGHT); // fall back to source height
}

Prevention

When it happens

Trigger: $image->resize(800, null, Enum::HEIGHT); - height omitted while the HEIGHT master is selected.

Common situations: Swapped argument order relative to the HEIGHT master; dynamic height values (e.g. from request input) arriving null; copying a WIDTH example and changing only the master constant.

Related errors


AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21). Data as JSON: /api/errors/435d082dbc518163. Report an issue: GitHub.

Appendix: source

Thrown at phalcon/Image/Adapter/AbstractAdapter.zep:583

        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) {
            return (this->width / width) > (this->height / height)
                ? Enum::WIDTH
                : Enum::HEIGHT;
        }

View on GitHub (pinned to b7419de9cd)