Intervention/image · error · InvalidArgumentException

Option ${key} does not exist on {this::class}

Error message

Option ${key} does not exist on {this::class}

What it means

Encoder options map directly to public properties of the concrete encoder class. setOptions() rejects any key that is not a property of that specific encoder: JpegEncoder has quality/progressive (plus inherited fields), PngEncoder has interlaced/indexed - and they do not share options.

Source

Thrown at src/Drivers/AbstractEncoder.php:69

    {
        $stream = self::buildStreamOrFail();
        $callback($stream);

        return is_string($mediaType) ? new EncodedImage($stream, $mediaType) : new EncodedImage($stream);
    }

    /**
     * {@inheritdoc}
     *
     * @see EncoderInterface::setOptions()
     *
     * @throws InvalidArgumentException
     */
    public function setOptions(mixed ...$options): self
    {
        foreach ($options as $key => $value) {
            if (!property_exists($this, (string) $key)) {
                throw new InvalidArgumentException(
                    'Option $' . $key . ' does not exist on ' . $this::class,
                );
            }
            $this->{$key} = $value;
        }

        return $this;
    }
}

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Use only options defined as public properties on the target encoder class (check e.g. src/Encoders/JpegEncoder.php)
  2. Drop format-specific options when switching formats - quality applies to JPEG/WebP, not PNG
  3. For smaller PNGs use the PNG-specific options (e.g. indexed) instead of quality

Example fix

// before
$encoded = $image->toPng(quality: 90);

// after
$encoded = $image->toPng(); // or: ->toPng(indexed: true)
Defensive patterns

Strategy: validation

Validate before calling

$allowed = array_keys(get_class_vars($encoder::class)); // public encoder options
$options = array_intersect_key($userOptions, array_flip($allowed));
$encoder->setOptions($options);

Prevention

When it happens

Trigger: $image->toPng(quality: 90) (PNG encoder has no quality property), $image->toJpg(indexed: true) (JPEG encoder has no indexed property), or any format-specific option passed to a different format's encoder via setOptions().

Common situations: Copy-pasting encode options between formats; assuming all encoders accept quality; options renamed or moved between major versions.

Related errors


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/109d19a188eac8d8. Report an issue: GitHub.